-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCCC-07-S3.c
52 lines (49 loc) · 1.09 KB
/
CCC-07-S3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <math.h>
#define ll long long
#define byte unsigned char
#define printi(a) printf("%d\n",a)
#define printii(a,b) printf("%d %d\n",a,b)
#define scani(a) scanf(" %d",&a)
#define scanii(a,b) scanf(" %d %d",&a,&b)
#define scanNewi(a) int a; scanf(" %d",&a)
#define scanNewii(a,b) int a,b; scanf(" %d %d",&a,&b)
#define fi(var, initial, max) for(int var=initial; var<max; ++var)
#define fd(var, initial, least) for(int var=initial; var>least; --var)
int main() {
int * people = calloc(10010, sizeof(int));
scanNewi(n);
int x, y;
fi(i, 0, n) {
scanii(x, y);
people[x] = y;
}
scanii(x, y);
int cur;
int sep;
int found;
while(!(x == 0 && y == 0)) {
cur = x;
sep = -1;
found = 0;
while((cur != x && cur != 0) || (cur == x && sep == -1)) {
if(cur == y) {
found = 1;
}
cur = people[cur];
if(!found) {
++sep;
}
}
if(found && cur == x) {
printf("Yes %d\n", sep);
} else {
printf("No\n");
}
scanii(x, y);
}
free(people);
return 0;
}