提交记录 6881


用户 题目 状态 得分 用时 内存 语言 代码长度
orbitingfIea 2002. 【NOIP2018】旅行(加强版) Time Limit Exceeded 70 1 s 52820 KB C++ 1.51 KB
提交时间 评测时间
2018-11-12 14:17:35 2020-08-01 00:52:42
#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[505000], cir[505000], tot, fa[505000], dep[505000];
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; if (max(n,m)>5e5) return 0; 
  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 #1437.83 us1 MB + 1008 KBAcceptedScore: 5

Testcase #2513.92 us1 MB + 1020 KBAcceptedScore: 5

Testcase #3468.24 us1 MB + 1012 KBAcceptedScore: 5

Testcase #4465.49 us1 MB + 1012 KBAcceptedScore: 5

Testcase #51.589 ms2 MB + 300 KBAcceptedScore: 5

Testcase #61.586 ms2 MB + 280 KBAcceptedScore: 5

Testcase #726.844 ms7 MB + 824 KBAcceptedScore: 5

Testcase #826.698 ms6 MB + 744 KBAcceptedScore: 5

Testcase #9146.315 ms31 MB + 800 KBAcceptedScore: 5

Testcase #10147.471 ms34 MB + 612 KBAcceptedScore: 5

Testcase #11146.787 ms26 MB + 428 KBAcceptedScore: 5

Testcase #12147.743 ms29 MB + 472 KBAcceptedScore: 5

Testcase #13184.644 ms2 MB + 392 KBAcceptedScore: 5

Testcase #14244.386 ms2 MB + 452 KBAcceptedScore: 5

Testcase #151 s9 MB + 244 KBTime Limit ExceededScore: 0

Testcase #161 s9 MB + 920 KBTime Limit ExceededScore: 0

Testcase #171 s51 MB + 596 KBTime Limit ExceededScore: 0

Testcase #181 s51 MB + 596 KBTime Limit ExceededScore: 0

Testcase #191 s36 MB + 44 KBTime Limit ExceededScore: 0

Testcase #201 s44 MB + 728 KBTime Limit ExceededScore: 0


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