# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
6159 | ainta | Senior Postmen (BOI14_postmen) | C++98 | 395 ms | 21368 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.
#pragma warning(disable:4996)
#include<stdio.h>
#include<algorithm>
int nxt[1000010], ed[1000010], num[500010];
int n, m, used[1000010], v[500010];
int st[500010];
void Do(int start){
int top = 0, x, y;
st[++top] = start;
v[start] = true;
while (1){
while (top){
while (used[num[st[top]]])num[st[top]] = nxt[num[st[top]]];
if (!num[st[top]]){
v[st[top]] = false;
top--;
}
else break;
}
if (!top)break;
x = st[top];
y = ed[num[x]];
used[num[x]] = used[num[x] ^ 1] = true;
num[x] = nxt[num[st[top]]];
if (v[y]){
while (1){
printf("%d ", st[top]);
if (st[top] == y)break;
v[st[top]] = false;
top--;
}
printf("\n");
continue;
}
else{
st[++top] = y;
v[y] = true;
}
}
v[start] = false;
}
int main()
{
int i, a, b, cnt = 1;
scanf("%d%d", &n, &m);
for (i = 0; i < m; i++){
scanf("%d%d", &a, &b);
ed[++cnt] = b; nxt[cnt] = num[a]; num[a] = cnt;
ed[++cnt] = a; nxt[cnt] = num[b]; num[b] = cnt;
}
for (i = 1; i <= n; i++){
Do(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... |