# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98420 | Kastanda | Senior Postmen (BOI14_postmen) | C++11 | 609 ms | 42912 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 N = 500005;
int n, m, cyc, from[N], to[N], M[N], S[N], ri[N];
int ts, st[N];
vector < int > Adj[N];
/*void DFS(int v)
{
S[v] = 1;
#define id (Adj[v][ri[v]])
#define u (from[id] ^ to[id] ^ v)
while (ri[v])
{
ri[v] --;
//int id = Adj[v][ri[v]];
if (M[id]) continue;
M[id] = 1;
//int u = from[id] ^ to[id] ^ v;
if (S[u])
{
cyc = u; S[v] = 0;
printf("%d", v);
return ;
}
DFS(u);
if (cyc)
printf(" %d", v);
if (cyc != v)
{
S[v] = 0;
return ;
}
else
cyc = 0, printf("\n");
}
#undef id
#undef u
S[v] = 0;
}*/
int v, u, id;
inline void DFS()
{
ts = 0;
st[++ ts] = v;
while (ts)
{
v = st[ts];
S[v] = 1;
while (ri[v] < (int)Adj[v].size())
{
id = (Adj[v][ri[v]]);
ri[v] ++;
u = (from[id] ^ to[id] ^ v);
if (M[id]) continue;
M[id] = 1;
if (S[u])
{
while (st[ts] != u)
{
printf("%d ", st[ts]);
S[st[ts]] = 0; ts --;
}
printf("%d\n", u);
ts ++;
break;
}
st[++ ts] = u;
ts ++;
break;
}
ts --;
}
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
{
scanf("%d%d", &from[i], &to[i]);
Adj[from[i]].push_back(i);
Adj[to[i]].push_back(i);
}
for (int i = 1; i <= n; i++)
ri[i] = 0;
for (int i = 1; i <= n; i++)
v = i, DFS();
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... |