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 p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
int n, m, a, b, t, p[500005];
bool u[500005], u2[500005];
vector<pii> v[500005];
vector<int> s, ans;
set<int> S;
void dfs(int N){
if (u[N]){
t=-1;
ans.clear();
while(t!=N){
ans.pb(t=s.back()); s.pop_back();
u[t]=0;
}
S.clear();
reverse(ans.begin(), ans.end());
fox(l, ans.size()){
printf("%i", ans[l]);
if (l!=ans.size()-1) printf(" ");
if (S.find(ans[l])!=S.end()) exit(1);
S.insert(ans[l]);
} printf("\n");
}
for(; p[N]<v[N].size(); ++p[N]){
if (!u2[v[N][p[N]].y]){
u[N]=1;
s.pb(N);
u2[v[N][p[N]].y]=1;
//e.pb(v[N][p[N]].y);
dfs(v[N][p[N]].x);
}
}
}
int main(){
//cin >> n >> m;
scanf("%i%i", &n, &m);
fox(l, m){
scanf("%i%i", &a, &b);
//a=l+1; b=(l==m-1 ? 1:l+2);
//scanf("%i%i", &a, &b);
v[a].pb(mp(b, l+1));
v[b].pb(mp(a, l+1));
}
dfs(1);
return 0;
}
Compilation message (stderr)
postmen.cpp: In function 'void dfs(int)':
postmen.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for (int k=0; k<x; ++k)
postmen.cpp:42:13:
fox(l, ans.size()){
~~~~~~~~~~~~~
postmen.cpp:42:9: note: in expansion of macro 'fox'
fox(l, ans.size()){
^~~
postmen.cpp:44:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (l!=ans.size()-1) printf(" ");
~^~~~~~~~~~~~~~
postmen.cpp:50:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; p[N]<v[N].size(); ++p[N]){
~~~~^~~~~~~~~~~~
postmen.cpp: In function 'int main()':
postmen.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
postmen.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i", &a, &b);
~~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |