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,lol;
vector<pii>v[500001];
bool visit[500001],fi,edge[500001];
stack<int>s,ss;
inline bool chk(int x)
{
if(!edge[x]){edge[x]=true;return true;}
else return false;
}
int read_int(){
char c;
bool check = 0;
int res = 0;
while(1){
c = getchar();
if (c == '-') {check = 1; continue;}
if (c == ' ' || c == '\n') break;
res = res*10 + c - '0';
}
if (check) return -res;
return res;
}
void push_db(int x)
{
if(!visit[x])
{
ss.push(x);
visit[x]=true;
return;
}
else
{
if(fi)printf("\n");
else fi=true;
while(1)
{
lol=ss.top();
if(lol!=x)printf("%d ",lol);
else printf("%d",lol);
if(lol!=x){visit[lol]=false;ss.pop();}
else break;
}
}
}
int x,y;
int main()
{
ios_base::sync_with_stdio(false);
n=read_int();
m=read_int();
for(int i=1;i<=m;++i)
{
x=read_int();
y=read_int();
++cnt;
v[x].push_back({y,cnt});
v[y].push_back({x,cnt});
}
s.push(1);
fi=false;
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();push_db(u);}
}
}
Compilation message (stderr)
postmen.cpp: In function 'int main()':
postmen.cpp:69:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[u].size();++i)
~^~~~~~~~~~~~
postmen.cpp:73:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(i==v[u].size()-1)vv=-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... |