# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
243973 | TadijaSebez | Senior Postmen (BOI14_postmen) | C++11 | 587 ms | 71268 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 pb push_back
const int N=500050;
int was[N],wse[N];
vector<pair<int,int>> E[N];
vector<int> tmp;
vector<vector<int>> ans;
int DFS(int u){
was[u]=1;
while(E[u].size()){
auto e=E[u].back();
if(wse[e.second])E[u].pop_back();
else{
int v=e.first;
wse[e.second]=1;
if(was[v]){
tmp.clear();
tmp.pb(u);
was[u]=0;
return v;
}else{
int t=DFS(v);
if(t!=u){
tmp.pb(u);
was[u]=0;
return t;
}
tmp.pb(u);
ans.pb(tmp);
}
}
}
return -1;
}
int main(){
int n,m;
scanf("%i %i",&n,&m);
for(int i=1,u,v;i<=m;i++)scanf("%i %i",&u,&v),E[u].pb({v,i}),E[v].pb({u,i});
for(int i=1;i<=n;i++)DFS(i);
for(auto cyc:ans){
for(int u:cyc)printf("%i ",u);
printf("\n");
}
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... |