提交记录 6887


用户 题目 状态 得分 用时 内存 语言 代码长度
shanjb020221 2002. 【NOIP2018】旅行(加强版) Wrong Answer 90 145.273 ms 65884 KB C++ 2.83 KB
提交时间 评测时间
2018-11-13 18:37:29 2020-08-01 00:53:06
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define IO(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define I(x) freopen(x".in","r",stdin)
#define R(x) freopen(x".ini","r",stdin),freopen(x".in","w",stdout)
using namespace std;
const int N=501000;
inline int read(){
    register char c=getchar(),d=0;
    while(c>'9'||c<'0')d=c,c=getchar();
    register int r=0;
    while(c>='0'&&c<='9')r=(r<<1)+(r<<3)+c-'0',c=getchar();
    return d=='-'?-r:r;
}
inline void wt(int x){
    if(x/10)wt(x/10);
    putchar(x%10+'0');
}
inline void wtln(int x){
    if(x<0)x=-x,putchar('-');
    wt(x),putchar('\n');
}
inline void wtsp(int x){
    if(x<0)x=-x,putchar('-');
    wt(x),putchar(' ');
}
struct edge{
    int to,nt;
    inline void init(int t,int n){
        to=t,nt=n;
    }
}e[N<<1];
int h[N],c=1,x,y;
inline void adde(int f,int t){
    e[++c].init(t,h[f]),h[f]=c;
    e[++c].init(f,h[t]),h[t]=c;
}
int n,m;
int ans[N],tot;
namespace solve1{
    int tmp[N],cnt;
    int vis[N];
    inline void dfs(int pos){
        vis[pos]=1;
        ans[++tot]=pos;
        int l=cnt,r;
        for(int i=h[pos];i;i=e[i].nt)
            if(!vis[e[i].to])tmp[cnt++]=e[i].to;
        r=cnt;
        sort(tmp+l,tmp+r);
        for(int i=l;i<r;++i)
            dfs(tmp[i]);
    }
}
namespace solve2{
    int dele,px,py;
    int ste[N],stp[N],top;
    int cre[N],crp[N],cc,vis[N];
    inline bool fndc(int pos,int pi=0){
        int tps;
        vis[pos]=1;
        for(int i=h[pos];i;i=e[i].nt){
            tps=e[i].to;
            if(i==pi)continue;
            ste[++top]=i;
            stp[top]=pos;
            if(vis[tps]){
                while(1){
                    cre[++cc]=ste[top];
                    crp[cc]=stp[top];
                    if(stp[top--]==tps)break;
                }
                return 1;
            }else if(fndc(tps,i^1))return 1;
            if(ste[top]==i)--top;
        }
        return 0;
    }
    int tmp[N],cnt;
    inline void dfs(int pos){
        vis[pos]=1;
        ans[++tot]=pos;
        int l=cnt,r;
        for(int i=h[pos];i;i=e[i].nt)
            if(i!=dele&&(i^1)!=dele&&!vis[e[i].to])tmp[cnt++]=e[i].to;
        r=cnt;
        sort(tmp+l,tmp+r);
        for(int i=l;i<r;++i)
            dfs(tmp[i]);
    }
    inline void MAIN(){
        fndc(1);
        px=crp[1],py=crp[cc-1];
        if(cc==2){
            dele=cre[1];
        }else if(px<py){
            int p=1;
            while(crp[p]<py)++p;
            dele=cre[p];
        }else {
            int p=cc-1;
            while(crp[p-1]<px)--p;
            dele=cre[p];
        }
        memset(vis,0,sizeof vis);
        dfs(1);
    }
}
int main(){
    //IO("travel");
    n=read(),m=read();
    for(int i=1;i<=m;++i)
        adde(read(),read());
    if(n==m+1)solve1::dfs(1);
    else solve2::MAIN();
    for(int i=1;i<n;++i)
        wtsp(ans[i]);
    wtln(ans[n]);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #135.75 us64 KBAcceptedScore: 5

Testcase #2192.94 us1 MB + 1008 KBAcceptedScore: 5

Testcase #340.16 us68 KBAcceptedScore: 5

Testcase #438.45 us68 KBAcceptedScore: 5

Testcase #5357.79 us376 KBAcceptedScore: 5

Testcase #6349.51 us360 KBAcceptedScore: 5

Testcase #710.604 ms5 MB + 932 KBAcceptedScore: 5

Testcase #810.418 ms5 MB + 100 KBAcceptedScore: 5

Testcase #994.114 ms29 MB + 916 KBAcceptedScore: 5

Testcase #1095.084 ms32 MB + 8 KBAcceptedScore: 5

Testcase #1195.018 ms25 MB + 892 KBAcceptedScore: 5

Testcase #1295.666 ms28 MB + 156 KBAcceptedScore: 5

Testcase #13634.53 us2 MB + 424 KBWrong AnswerScore: 0

Testcase #14618.85 us2 MB + 508 KBWrong AnswerScore: 0

Testcase #1513.466 ms10 MB + 616 KBAcceptedScore: 5

Testcase #1613.581 ms11 MB + 548 KBAcceptedScore: 5

Testcase #17144.353 ms64 MB + 348 KBAcceptedScore: 5

Testcase #18145.273 ms64 MB + 348 KBAcceptedScore: 5

Testcase #19130.224 ms42 MB + 416 KBAcceptedScore: 5

Testcase #20139.366 ms54 MB + 652 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2025-10-31 03:46:53 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠