# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
25995 | H_H | Senior Postmen (BOI14_postmen) | C++14 | 553 ms | 57592 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;
const int MAXN=500005;
bool vis[MAXN];
bool vs[MAXN];
vector<pair<int,int> >adj[MAXN];
int it[MAXN];
int n,m;
int cyc=-1;
void dfs(int x)
{
vis[x]=true;
while(it[x]<adj[x].size())
{
int i=it[x];
int y=adj[x][i].first;
int in=adj[x][i].second;
if(vs[in])
{
it[x]++;
continue;
}
it[x]++;
vs[in]=true;
if(vis[y])
{
printf("%d",x);
cyc=y;
break;
}
dfs(y);
if(cyc!=-1)
{
printf(" %d",x);
if(cyc==x)
{
printf("\n");
cyc=-1;
}
else break;
}
}
vis[x]=false;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
adj[x].push_back({y,i});
adj[y].push_back({x,i});
}
for(int i=1;i<=n;i++)dfs(i);
return 0;
}
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... |