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 fi first
#define se second
typedef pair<int,int> pii;
int n,m,vv,u,cnt;
vector<pair<int,int> >v[500001];
bool visit[500001],fi,edge[500001];
vector<int>ans;
stack<int>s;
bool chk(int x)
{
if(!edge[x]){edge[x]=true;return true;}
else return false;
}
int x,y;
int main()
{
ios_base::sync_with_stdio(false);
cin>>n>>m;
for(int i=1;i<=m;++i)
{
cin>>x>>y;
++cnt;
v[x].push_back({y,cnt});
v[y].push_back({x,cnt});
}
s.push(1);
while(!s.empty())
{
u=s.top();
for(int i=0;i<v[u].size();++i)
{
vv=v[u][i].fi;
if(chk(v[u][i].se))break;
if(i==v[u].size()-1)vv=-1;
}
if(vv!=-1)s.push(vv);
else {s.pop();ans.push_back(u);}
}
fi=false;
for(int i=0;i<ans.size();++i)
{
if(!visit[ans[i]])
{
s.push(ans[i]);
visit[ans[i]]=true;
}
else
{
if(fi)cout<<endl;
else fi=true;
while(1)
{
if(s.top()!=ans[i])cout<<s.top()<<' ';
else cout<<s.top();
if(s.top()!=ans[i]){visit[s.top()]=false;s.pop();}
else break;
}
}
}
}
Compilation message (stderr)
postmen.cpp: In function 'int main()':
postmen.cpp:32:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[u].size();++i)
~^~~~~~~~~~~~
postmen.cpp:36:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(i==v[u].size()-1)vv=-1;
~^~~~~~~~~~~~~~~
postmen.cpp:42:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ans.size();++i)
~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |