# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
14817 | eaststar | Senior Postmen (BOI14_postmen) | C++98 | 437 ms | 19560 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 <stdio.h>
int s[500010],e[500010],cnt[500010],a[1000010],visit[500010],chk[500010],p[500010];
void ans(int k){
int t,l;
for(;;k=l){
int&n=cnt[k];
for(;(s[a[n]]==k||e[a[n]]==k)&&chk[a[n]];++n);
if(s[a[n]]!=k&&e[a[n]]!=k)return;
visit[k]=chk[a[n]]=1;
l=s[a[n]]==k? e[a[n]]:s[a[n]];
if(visit[l]){
t=k;
for(;t!=l;t=p[t]){
visit[t]=0;
printf("%d ",t);
}
printf("%d\n",t);
}
else p[l]=k;
}
}
int main(){
int i,n,m;
scanf("%d%d",&n,&m);
for(i=1;i<=m;++i){
scanf("%d%d",s+i,e+i);
++cnt[s[i]],++cnt[e[i]];
}
for(i=1;i<=n;++i)cnt[i]+=cnt[i-1];
for(i=1;i<=m;++i)a[--cnt[s[i]]]=a[--cnt[e[i]]]=i;
for(i=1;i<=n;++i)ans(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... |