#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,vv,u,visit[500001],fi;
map<pair<int,int>,bool>mp;
vector<int>v[500001],ans;
stack<int>s;
int main()
{
cin>>n>>m;
for(int i=1;i<=m;++i)
{
cin>>x>>y;
mp[{x,y}]=true;
mp[{y,x}]=true;
v[x].push_back(y);
v[y].push_back(x);
}
s.push(1);
while(!s.empty())
{
u=s.top();
for(int i=0;i<v[u].size();++i)
{
vv=v[u][i];
if(mp[{vv,u}]==true)
{
mp[{vv,u}]=false;
mp[{u,vv}]=false;
break;
}
if(i==v[u].size()-1)vv=-1;
}
if(vv!=-1)s.push(vv);
else {s.pop();ans.push_back(u);}
}
fi=0;
for(int i=0;i<ans.size();++i)
{
if(visit[ans[i]]==0)
{
s.push(ans[i]);
visit[ans[i]]=1;
}
else
{
if(fi==1)cout<<endl;
else fi=1;
while(1)
{
if(s.top()!=ans[i])cout<<s.top()<<' ';
else cout<<s.top();
if(s.top()!=ans[i]){visit[s.top()]=0;s.pop();}
else break;
}
}
}
}
Compilation message
postmen.cpp: In function 'int main()':
postmen.cpp:22:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[u].size();++i)
~^~~~~~~~~~~~
postmen.cpp:31:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(i==v[u].size()-1)vv=-1;
~^~~~~~~~~~~~~~~
postmen.cpp:37: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 |
1 |
Correct |
14 ms |
12032 KB |
Output is correct |
2 |
Correct |
12 ms |
12032 KB |
Output is correct |
3 |
Correct |
13 ms |
12032 KB |
Output is correct |
4 |
Correct |
297 ms |
12576 KB |
Output is correct |
5 |
Correct |
30 ms |
12288 KB |
Output is correct |
6 |
Correct |
118 ms |
12792 KB |
Output is correct |
7 |
Execution timed out |
855 ms |
14456 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12008 KB |
Output is correct |
2 |
Correct |
12 ms |
12032 KB |
Output is correct |
3 |
Correct |
12 ms |
12160 KB |
Output is correct |
4 |
Correct |
284 ms |
12608 KB |
Output is correct |
5 |
Correct |
20 ms |
12288 KB |
Output is correct |
6 |
Correct |
113 ms |
12752 KB |
Output is correct |
7 |
Execution timed out |
827 ms |
14360 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
12032 KB |
Output is correct |
2 |
Correct |
12 ms |
12032 KB |
Output is correct |
3 |
Correct |
13 ms |
12160 KB |
Output is correct |
4 |
Correct |
286 ms |
12520 KB |
Output is correct |
5 |
Correct |
26 ms |
12288 KB |
Output is correct |
6 |
Correct |
108 ms |
12748 KB |
Output is correct |
7 |
Execution timed out |
832 ms |
14404 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |