# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
17658 | Namnamseo | Senior Postmen (BOI14_postmen) | C++14 | 399 ms | 20012 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 <cstdio>
#include <vector>
int n,m;
int start[ 500010];
int endp [1000010];
int next [1000010];
bool dead[1000010];
int counter;
void addEdge(int from,int to)
{
next [counter] = start[from];
start[from ] = counter;
endp [counter] = to;
++counter;
}
int stack[500010];
int hi [500010];
int top=-1;
void push(int x) { stack[++top]=x; }
int pop ( ) { return stack[top--]; }
bool visited[500010];
int main()
{
counter=1;
scanf("%d%d",&n,&m);
int i,a,b;
for(i=0;i<m;i++){
scanf("%d%d",&a,&b);
addEdge(a,b);
addEdge(b,a);
}
push(1);
int cur;
int t=0;
while(top>=0)
{
cur=stack[top];
while(dead[start[cur]] && start[cur]) {
start[cur]=next[start[cur]];
}
if(start[cur]==0) {
hi[t++]=cur;
--top;
continue;
} else {
push(endp[start[cur]]);
dead[start[cur]]=true;
if(start[cur]%2){
dead[start[cur]+1]=true;
} else dead[start[cur]-1]=true;
}
}
top=-1;
int temp;
for(i=0;i<t;++i)
{
cur = hi[i];
//printf("%d ",cur);
if(visited[cur])
{
while((temp=pop())!=cur) {
printf("%d ",temp);
visited[temp]=false;
}
printf("%d\n",cur);
push(cur);
} else {
visited[cur]=true;
push(cur);
}
}
}
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... |