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;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define fox(k, x) for (int k=0; k<x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
int n, m, a, b, t, d, p[500005], s[500005];
bool u[500005], u2[500005];
vector<pii> v[500005];
vector<int> ans;
void dfs(int N){
if (u[N]){
t=-1;
ans=vector<int>();
while(t!=N){
t=s[--d];
u[t]=0;
printf("%i", t);
if (t!=N) printf(" ");
}
printf("\n");
}
int k=v[N].size();
for(; p[N]<k; ++p[N]){
if (!u2[v[N][p[N]].y]){
u2[v[N][p[N]].y]=u[N]=1;
s[d++]=N;
dfs(v[N][p[N]].x);
}
}
}
int main(){
scan(n); scan(m);
fox(l, m){
scan(a); scan(b);
v[a].pb(mp(b, l));
v[b].pb(mp(a, l));
}
dfs(1);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |