This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
vi mp;
vvi g;
vi path;
vi vis;
ll map_hash(ll a, ll b){
if(a>b) swap(a,b);
return a*1e5+b;
}
void dfs(int u){
path.push_back(u);
//cout<<u<<" "<<vis[u]<<endl;
if(vis[u]==true){
// cout<<"hola"<<endl;
int x = u;
// cout<<"a"<<endl;
int size=(int)path.size()-1;
// cout<<size<<endl;
do{
//cout<<size<<endl;
cout<<path[size]<<" ";
vis[path[size]]=false;
path.pop_back();
size=(int)path.size()-1;
//cout<<size<<endl;
}while(path[size]!=x && size>0);
cout<<'\n';
}
vis[u]=true;
for(auto v: g[u]){
vis[u]=true;
int a=u, b=v;
if(mp[map_hash(a, b)]!=1){
// cout<<a<<" "<<b<<endl;
mp[map_hash(a, b)]=1;
dfs(v);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin>>n>>m;
g.resize(n+1,vi());
vis.resize(n+1,0);
mp.resize(1e7,0);
for(int i=0; i<m; i++){
int a,b;
cin>>a>>b;
mp[map_hash(a, b)] = 0;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |