提交记录 6883


用户 题目 状态 得分 用时 内存 语言 代码长度
q234rty 2002. 【NOIP2018】旅行(加强版) Runtime Error 30 1.181 ms 4808 KB C++ 2.06 KB
提交时间 评测时间
2018-11-12 18:45:18 2020-08-01 00:52:50
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
using namespace std;
inline LL read(){
    char c=getchar();while (c!='-'&&(c>'9'||c<'0'))c=getchar();
    LL k=0,kk=1;if (c=='-')kk=-1,c=getchar();
    while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return k*kk;
}void write(LL x){if (x<0)putchar('-'),x=-x;if (x/10)write(x/10);putchar(x%10+'0');}
void writeln(LL x){write(x);puts("");}
int ff[10010],l[10010],r[10010],x,y,n,m,faq;
int flag[10010],fh[10010],ffa[10010];
vector<int>v[10010];
void clc(int x,int fa){//求出基环树上所有点 
    int d=v[x].size();fh[x]=fa;flag[x]=1;
    for (int i=0;i<d&&!faq;i++)if (v[x][i]!=fa){
        if (flag[v[x][i]]&&!faq){
            ff[x]=1;int dd=v[x][i];
            while (x!=dd)x=fh[x],ff[x]=1;
            faq=1;return;
        }else clc(v[x][i],x);
    }
}
signed main(){
// 	freopen("travel.in","r",stdin);freopen("travel.out","w",stdout);
    n=read();m=read();
    for (int i=1;i<=m;i++)x=read(),y=read(),v[x].pb(y),v[y].pb(x);
    if (n==m)clc(1,0);faq=0;
    for (int i=1;i<=n;i++){
        flag[i]=fh[i]=0;
        l[i]=0;r[i]=v[i].size()-1;
        v[i].pb(0);sort(&v[i][0],&v[i][r[i]+1]);
    }int d=1;
    for (int i=1;i<=n;i++){
        write(d);if (i!=n)putchar(' ');flag[d]=1;
    //	if (i==9)cout<<1<<endl;
        while (flag[v[d][l[d]]]&&l[d]<=r[d])l[d]++;
        while(l[d]>r[d]){
            d=fh[d];if (d==0)break;
            while (flag[v[d][l[d]]]&&l[d]<=r[d])l[d]++;
        }if (d==0)break;
    //	if (i==9)cout<<endl<<' '<<v[d][0]<<' '<<v[d][1]<<endl;
        if (ff[d]&&!faq&&l[d]==r[d]&&ff[v[d][l[d]]]){
            //遍历完除了环以外的所有孩子的时候可以向上跳
            int j=fh[d];
            while (flag[v[j][l[j]]]&&l[j]<=r[j])l[j]++;
            while (ff[j]&&l[j]>r[j]){//向上找第一个有儿子的环上点 
                j=ffa[j];if (!j)break;
                while (flag[v[j][l[j]]]&&l[j]<=r[j])l[j]++;
            }ffa[d]=j;
            if (j&&ff[j]&&flag[j]){
                while (flag[v[j][l[j]]]&&l[j]<=r[j])l[j]++;
                if (l[j]<=r[j]&&v[j][l[j]]<v[d][l[d]])d=j,faq=1;
            }
        }fh[v[d][l[d]]]=d;d=v[d][l[d]];
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #165.78 us288 KBAcceptedScore: 5

Testcase #274.16 us292 KBAcceptedScore: 5

Testcase #392.07 us292 KBAcceptedScore: 5

Testcase #484.64 us292 KBAcceptedScore: 5

Testcase #51.03 ms540 KBAcceptedScore: 5

Testcase #61.021 ms540 KBAcceptedScore: 5

Testcase #7154.29 us1 MB + 56 KBRuntime ErrorScore: 0

Testcase #895.3 us608 KBRuntime ErrorScore: 0

Testcase #9165.46 us1 MB + 140 KBRuntime ErrorScore: 0

Testcase #10606.6 us4 MB + 712 KBRuntime ErrorScore: 0

Testcase #11496.48 us3 MB + 824 KBRuntime ErrorScore: 0

Testcase #121.181 ms2 MB + 200 KBRuntime ErrorScore: 0

Testcase #131.174 ms824 KBWrong AnswerScore: 0

Testcase #141.181 ms892 KBWrong AnswerScore: 0

Testcase #1565.61 us344 KBRuntime ErrorScore: 0

Testcase #1658.57 us284 KBRuntime ErrorScore: 0

Testcase #1791.69 us560 KBRuntime ErrorScore: 0

Testcase #18179.32 us1 MB + 264 KBRuntime ErrorScore: 0

Testcase #19291.85 us2 MB + 180 KBRuntime ErrorScore: 0

Testcase #20490.92 us3 MB + 820 KBRuntime ErrorScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-09 08:51:05 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠