提交记录 6880


用户 题目 状态 得分 用时 内存 语言 代码长度
orbitingfIea 2002. 【NOIP2018】旅行(加强版) Runtime Error 70 285.722 ms 588872 KB C++ 1.47 KB
提交时间 评测时间
2018-11-12 14:14:20 2020-08-01 00:52:36
#include<bits/stdc++.h>
using namespace std;
 
int n, m, hea[505000], to[1001000], ban1=-1, ban2=-1;
int ui[505000], vi[505000], ans[505000], st[505000], tp, win;
 
void dfs(int x,int fff){
  st[++tp]=x;
  if (win==0&&st[tp]!=ans[tp]){
    win=st[tp]<ans[tp]? 1: -1;
  }
  if (win==-1) return;
  for (int i=hea[x];i<hea[x+1];++i)
    if (to[i]!=fff&&i!=ban1&&i!=ban2){
      dfs(to[i],x);
    }
}
 
void realmain(){
  tp=0; win=0;
  dfs(1,0);
  if (win==1) memcpy(ans,st,sizeof ans);
}
 
void BAN(int u,int v){
  ban1=lower_bound(to+hea[u],to+hea[u+1],v)-to;
  ban2=lower_bound(to+hea[v],to+hea[v+1],u)-to;
}
 
int usd[5050], cir[5050], tot, fa[5050], dep[5050];
void getcir(int x,int fff){
  usd[x]=1;
  dep[x]=dep[fff]+1; fa[x]=fff;
  for (int i=hea[x];i<hea[x+1];++i){
    int y=to[i]; if (y==fff) continue;
    if (!usd[y]) getcir(y,x);
    else if (dep[x]>dep[y]){
      for (int t=x;t!=y;t=fa[t])
    cir[tot++]=t;
      cir[tot++]=y;
    }
  }
}
 
int main(){
  cin>>n>>m; int u, v;
  for (int i=1;i<=m;++i){
    scanf("%d%d",&u,&v);
    ++hea[u]; ++hea[v];
    ui[i]=u; vi[i]=v;
  }
  for (int i=1;i<=n+1;++i) hea[i]+=hea[i-1];
  for (int i=1;i<=m;++i){
    u=ui[i]; v=vi[i];
    to[--hea[u]]=v;
    to[--hea[v]]=u;
  }
  for (int i=1;i<=n;++i)
    sort(to+hea[i],to+hea[i+1]);
  memset(ans,33,sizeof ans);
  if (m==n-1) realmain();
  else{
    getcir(1,0);
    for (int i=0;i<tot;++i){
      BAN(cir[i],cir[(i+1)%tot]);
      realmain();
    }
  }
  for (int i=1;i<=n;++i) printf("%d ",ans[i]);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1441.6 us1 MB + 1008 KBAcceptedScore: 5

Testcase #2516.92 us1 MB + 1020 KBAcceptedScore: 5

Testcase #3472.47 us1 MB + 1008 KBAcceptedScore: 5

Testcase #4464.56 us1 MB + 1008 KBAcceptedScore: 5

Testcase #51.584 ms2 MB + 296 KBAcceptedScore: 5

Testcase #61.574 ms2 MB + 276 KBAcceptedScore: 5

Testcase #726.771 ms7 MB + 828 KBAcceptedScore: 5

Testcase #826.665 ms6 MB + 748 KBAcceptedScore: 5

Testcase #9146.955 ms31 MB + 796 KBAcceptedScore: 5

Testcase #10147.98 ms34 MB + 608 KBAcceptedScore: 5

Testcase #11147.472 ms26 MB + 424 KBAcceptedScore: 5

Testcase #12148.322 ms29 MB + 468 KBAcceptedScore: 5

Testcase #13184.897 ms2 MB + 376 KBAcceptedScore: 5

Testcase #14245.92 ms2 MB + 436 KBAcceptedScore: 5

Testcase #15243.56 ms575 MB + 72 KBRuntime ErrorScore: 0

Testcase #16243.45 ms575 MB + 72 KBRuntime ErrorScore: 0

Testcase #17282.258 ms575 MB + 64 KBRuntime ErrorScore: 0

Testcase #18282.279 ms575 MB + 64 KBRuntime ErrorScore: 0

Testcase #19285.722 ms575 MB + 72 KBRuntime ErrorScore: 0

Testcase #20284.321 ms575 MB + 60 KBRuntime ErrorScore: 0


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