QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#509651#5720. Coloring ContentionexxqfuAC ✓7ms4060kbC++141.0kb2024-08-08 16:53:032024-08-08 16:53:03

Judging History

你现在查看的是最新测评结果

  • [2024-08-08 16:53:03]
  • 评测
  • 测评结果:AC
  • 用时:7ms
  • 内存:4060kb
  • [2024-08-08 16:53:03]
  • 提交

answer

#include <cstdio>
#define rep(i, d, u) for(int i = d; i <= u; ++i)
#define gep(i, a) for(int i = firs[a]; i; i = neig[i])
int ured() {
	int ch, re = 0;
	do {
		ch = getchar();
	} while(ch < '0' || '9' < ch);
	do {
		re = re * 10 + (ch ^ '0');
	} while('0' <= (ch = getchar()) && ch <= '9');
	return re;
}
void uwit(int da) {
	int ch[21], cn = 0;
	do {
		ch[++cn] = da % 10;
	} while(da /= 10);
	do {
		putchar('0' ^ ch[cn]);
	} while(--cn);
}
const int _maxn = 100011, _maxm = 100011;
int n, m, u, v, firs[_maxn], neig[_maxm << 1], arri[_maxm << 1], queu[_maxn], dist[_maxn], head, tail;
int main() {
	n = ured(), m = ured();
	rep(i, 1, m) {
		u = ured(), v = ured(), neig[i << 1] = firs[u], firs[u] = i << 1, arri[i << 1] = v;
		neig[i << 1 | 1] = firs[v], firs[v] = i << 1 | 1, arri[i << 1 | 1] = u;
	}
	dist[queu[++tail] = 1] = 1;
	while(head < tail) {
		gep(i, queu[++head]) {
			if(!dist[arri[i]]) {
				dist[queu[++tail] = arri[i]] = dist[queu[head]] + 1;
			}
		}
	}
	uwit(dist[n] - 2), putchar('\n');
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 1284kb

input:

3 3
1 3
1 2
2 3

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 0ms
memory: 1236kb

input:

7 8
1 2
1 3
2 4
3 4
4 5
4 6
5 7
6 7

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 0ms
memory: 4060kb

input:

100000 99999
1 82839
79117 1
52850 1
1 98692
1 97570
1 52713
1 69481
86347 1
1 78467
32605 1
1 50497
32776 1
96243 1
1 63191
1 40685
6039 1
42700 1
36636 1
14590 1
89412 1
96386 1
1 67084
74195 1
79616 1
1 7286
1 85081
82925 1
31913 1
1 21516
32383 1
1 57458
12240 1
1 93520
1 34296
36228 1
1 75440
1...

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 7ms
memory: 3952kb

input:

100000 99999
27258 66566
49213 38165
7349 35601
47068 59589
82972 21228
78010 70856
22573 21068
82303 88214
70714 58816
56991 82670
85959 16532
78640 33897
24436 19989
65698 53247
26936 48520
98934 34959
8790 31287
14159 78214
57169 40287
76148 2201
86479 91453
5488 41694
74869 54823
89247 61215
519...

output:

539

result:

ok single line: '539'

Test #5:

score: 0
Accepted
time: 4ms
memory: 3968kb

input:

100000 99999
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 5...

output:

99998

result:

ok single line: '99998'

Test #6:

score: 0
Accepted
time: 0ms
memory: 1356kb

input:

1000 999
932 823
327 977
686 691
953 794
15 119
737 388
990 974
288 352
61 902
788 623
663 359
127 339
90 326
932 444
186 618
720 711
19 212
903 485
701 981
374 798
704 682
448 9
392 995
876 919
654 865
666 779
96 42
398 791
270 52
100 789
934 153
530 384
42 672
85 190
155 212
958 671
875 109
548 90...

output:

21

result:

ok single line: '21'

Test #7:

score: 0
Accepted
time: 7ms
memory: 3452kb

input:

50000 100000
28248 18492
26576 35631
24372 31335
21157 22858
37902 38986
11853 43294
35768 24957
2945 47238
40691 23555
48511 1145
47818 23856
35634 28018
18986 21852
14548 26616
21720 31959
1729 35365
44893 33526
42275 45406
31524 40636
43336 37450
25680 10313
3194 30926
25840 49649
46576 39236
293...

output:

6

result:

ok single line: '6'

Test #8:

score: 0
Accepted
time: 7ms
memory: 4024kb

input:

100000 100000
97704 13532
27204 2673
19841 84042
48327 54969
71398 52260
12390 8666
3134 99125
1845 87343
81343 66766
54927 55648
90987 43060
53891 26643
6776 51388
68906 31243
87461 3210
3427 18338
42562 41129
10053 95408
94091 93657
49139 47047
47819 15659
93856 95840
10 99328
68544 41752
10913 82...

output:

634

result:

ok single line: '634'

Test #9:

score: 0
Accepted
time: 0ms
memory: 1328kb

input:

1000 5000
308 693
826 327
86 323
397 883
952 580
658 1000
466 122
579 993
68 238
2 41
94 325
162 534
728 976
23 862
730 895
134 669
712 96
174 895
297 931
969 813
526 357
420 317
971 425
165 506
373 748
422 206
921 299
397 67
990 837
774 798
692 685
393 231
453 332
36 675
873 156
475 676
20 221
141 ...

output:

3

result:

ok single line: '3'

Test #10:

score: 0
Accepted
time: 0ms
memory: 1236kb

input:

10 20
10 7
9 8
8 6
9 5
1 7
8 10
3 7
3 9
6 1
2 3
5 7
8 4
6 4
5 8
8 2
4 10
10 5
2 9
6 9
10 3

output:

1

result:

ok single line: '1'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3368kb

input:

100 99
13 73
55 31
76 8
58 68
82 33
11 75
50 36
21 42
10 90
69 71
68 9
57 53
14 67
45 55
24 5
50 74
16 95
46 37
35 41
22 65
75 64
92 12
26 37
61 51
92 87
14 44
100 58
71 94
19 2
7 63
60 63
30 24
13 70
56 55
78 28
40 97
96 19
58 45
13 40
20 21
90 64
9 81
99 73
60 23
67 7
28 83
27 4
71 12
54 82
77 21
...

output:

13

result:

ok single line: '13'