Submission #68155125


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N=3e5+10;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
map<int,int> mp;
int n,m,k;
int a[N],b[N];
void slove(){
    int x,y;
    cin>>n>>m>>x>>y;
    vector<int> vis(n+1,0);
    vector<vector<int>> q(n+1);
    for(int i=1;i<=m;i++){
        int u,v;cin>>u>>v;
        q[u].push_back(v);
        q[v].push_back(u);
    }
    vector<int> ans;
    auto dfs=[&](auto &&self,int u)->int{
        vis[u]=1;
        if(u==y){
            return 1;
        }
        priority_queue<int,vector<int>,greater<int>> p;
        for(auto t:q[u]){
            if(vis[t]) continue;
            p.push(t);
        }
        if(p.empty()) return 0;
        while(!p.empty()){
            int v=p.top();
            p.pop();
            if(self(self,v)==1){
                ans.push_back(v);
                return 1;
            }
        }
        return 0;
    };
    vis[x]=1;
    dfs(dfs,x);
    ans.push_back(x);
    for(int i=ans.size()-1;i>=0;i--){
        cout<<ans[i]<<' ';
    }cout<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
    int T=1;
    cin>>T;
    while(T--){
        slove();
    }
}

Submission Info

Submission Time
Task E - A Path in A Dictionary
User Maikan
Language C++ 20 (gcc 12.2)
Score 475
Code Size 1254 Byte
Status AC
Exec Time 22 ms
Memory 5488 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 1
AC × 43
Set Name Test Cases
Sample example_00.txt
All example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3484 KiB
hand_00.txt AC 7 ms 5356 KiB
hand_01.txt AC 1 ms 3804 KiB
hand_02.txt AC 22 ms 5400 KiB
hand_03.txt AC 1 ms 3668 KiB
hand_04.txt AC 5 ms 3616 KiB
hand_05.txt AC 6 ms 5488 KiB
hand_06.txt AC 22 ms 5484 KiB
hand_07.txt AC 1 ms 3520 KiB
hand_08.txt AC 9 ms 4836 KiB
hand_09.txt AC 6 ms 5160 KiB
hand_10.txt AC 1 ms 3736 KiB
hand_11.txt AC 1 ms 3484 KiB
random_00.txt AC 1 ms 3556 KiB
random_01.txt AC 1 ms 3436 KiB
random_02.txt AC 1 ms 3480 KiB
random_03.txt AC 1 ms 3496 KiB
random_04.txt AC 1 ms 3572 KiB
random_05.txt AC 2 ms 3500 KiB
random_06.txt AC 1 ms 3544 KiB
random_07.txt AC 1 ms 3512 KiB
random_08.txt AC 1 ms 3508 KiB
random_09.txt AC 2 ms 3668 KiB
random_10.txt AC 3 ms 3684 KiB
random_11.txt AC 3 ms 3576 KiB
random_12.txt AC 1 ms 3360 KiB
random_13.txt AC 1 ms 3504 KiB
random_14.txt AC 2 ms 3484 KiB
random_15.txt AC 4 ms 3648 KiB
random_16.txt AC 4 ms 3712 KiB
random_17.txt AC 6 ms 3716 KiB
random_18.txt AC 1 ms 3464 KiB
random_19.txt AC 1 ms 3488 KiB
random_20.txt AC 6 ms 5052 KiB
random_21.txt AC 2 ms 3604 KiB
random_22.txt AC 6 ms 4248 KiB
random_23.txt AC 18 ms 5416 KiB
random_24.txt AC 1 ms 3504 KiB
random_25.txt AC 1 ms 3768 KiB
random_26.txt AC 6 ms 5224 KiB
random_27.txt AC 6 ms 5084 KiB
random_28.txt AC 6 ms 5088 KiB
random_29.txt AC 6 ms 5256 KiB