# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
31550 | Kanvie | Senior Postmen (BOI14_postmen) | C++14 | 1082 ms | 16504 KiB |
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];
vector<int>ans;
stack<int>s,ss;
inline bool chk(int x)
{
if(!edge[x]){edge[x]=true;return true;}
else return false;
}
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()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;++i)
{
scanf("%d%d",&x,&y);
++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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |