Submission #1729775


Source Code Expand

#include<stdio.h>
int c[100010],ta[100010],to[200010],nt[200010];
int f(int s){//printf("%d %d\n",s,c[s]);
  int i,r;
  for(i=ta[s];i+1;i=nt[i]){//printf(":%d\n",to[i]);
    if(c[to[i]]==c[s]-1)continue;
    if(c[to[i]])return c[s]-c[to[i]]+1;
    c[to[i]]=c[s]+1;
    r=f(to[i]);
    if(r)return r;
  }
  return 0;
}
int main(){
  int n,i,a,b;
  scanf("%d",&n);
  for(i=0;i<n;i++)ta[i+1]=-1;
  for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    nt[i]=ta[a];
    ta[a]=i;
    to[i]=b;
    nt[i+n]=ta[b];
    to[i+n]=a;
    ta[b]=i+n;
  }
  c[1]=2;
  printf("%d\n",f(1));
  return 0;
}

Submission Info

Submission Time
Task F - ループを探せ
User yuiop
Language C (GCC 5.4.1)
Score 100
Code Size 612 Byte
Status AC
Exec Time 28 ms
Memory 5632 KB

Compile Error

./Main.c: In function ‘main’:
./Main.c:16:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&n);
   ^
./Main.c:19:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&a,&b);
     ^

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 29
Set Name Test Cases
All 00-sample-00, 00-sample-01, 10-cycle-00, 10-cycle-01, 10-cycle-02, 10-cycle-03, 10-cycle-04, 10-cycle-05, 20-star-00, 20-star-01, 20-star-02, 20-star-03, 20-star-04, 30-binary-00, 30-binary-01, 30-binary-02, 30-binary-03, 40-random-00, 40-random-01, 40-random-02, 40-random-05, 40-random-06, 40-random-07, 40-random-10, 40-random-11, 40-random-12, 40-random-15, 40-random-16, 40-random-17
Case Name Status Exec Time Memory
00-sample-00 AC 1 ms 128 KB
00-sample-01 AC 1 ms 128 KB
10-cycle-00 AC 1 ms 128 KB
10-cycle-01 AC 1 ms 128 KB
10-cycle-02 AC 1 ms 128 KB
10-cycle-03 AC 1 ms 256 KB
10-cycle-04 AC 3 ms 768 KB
10-cycle-05 AC 28 ms 5632 KB
20-star-00 AC 1 ms 128 KB
20-star-01 AC 1 ms 128 KB
20-star-02 AC 1 ms 128 KB
20-star-03 AC 2 ms 384 KB
20-star-04 AC 20 ms 2560 KB
30-binary-00 AC 1 ms 128 KB
30-binary-01 AC 1 ms 128 KB
30-binary-02 AC 2 ms 384 KB
30-binary-03 AC 21 ms 2560 KB
40-random-00 AC 1 ms 128 KB
40-random-01 AC 1 ms 128 KB
40-random-02 AC 1 ms 128 KB
40-random-05 AC 1 ms 128 KB
40-random-06 AC 1 ms 128 KB
40-random-07 AC 1 ms 128 KB
40-random-10 AC 2 ms 384 KB
40-random-11 AC 2 ms 384 KB
40-random-12 AC 2 ms 384 KB
40-random-15 AC 20 ms 2560 KB
40-random-16 AC 23 ms 2560 KB
40-random-17 AC 21 ms 2560 KB