QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#163169#5088. Two Choreographiesstd_absAC ✓69ms20080kbC++202.0kb2023-09-03 21:36:432023-09-03 21:36:43

Judging History

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

  • [2023-09-03 21:36:43]
  • 评测
  • 测评结果:AC
  • 用时:69ms
  • 内存:20080kb
  • [2023-09-03 21:36:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
const int mod = 998244353, N = 100001;

typedef pair<int, int> pi;
vector<int> g[N];
int dep[N], pa[N];
map<int, pi> mp;
int rt[N], cnt[N];
int find(int i) {
	return rt[i] < 0 ? i : (rt[i] = find(rt[i]));
}
void onion(int i, int j) {
	i = find(i), j = find(j);
	if (i != j)
		rt[i] += rt[j], rt[j] = i;
}
bool vis[N];
void dfs(int i, int p) {
	vis[i] = true;
	pa[i] = p, dep[i] = ~p ? dep[p] + 1 : 0;
	for (int j : g[i])
		if (!vis[j])
			dfs(j, i);
}
int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n;
	cin >> n;
	fill(rt, rt + n, -1);
	for (int i = 0; i < 2 * n - 3; ++i) {
		int x, y;
		cin >> x >> y;
		--x, --y;
		g[x].push_back(y), g[y].push_back(x);
		onion(x, y);
	}
	for (int i = 0; i < n; ++i)
		cnt[find(i)] += g[i].size();
	for (int i = 0; i < n; ++i)
		if (rt[i] <= -3 && cnt[i] / 2 >= 2 * (-rt[i]) - 3) {
			dfs(i, -1);
			for (int x = 0; x < n; ++x)
				if (vis[x]) {
					for (int y : g[x])
						if (dep[y] < dep[x] && y != pa[x]) {
							if (mp.count(dep[x] - dep[y])) {
								cout << dep[x] - dep[y] + 1 << '\n';
								int l = mp[dep[x] - dep[y]].first, r = mp[dep[x] - dep[y]].second;
								while (l != r)
									cout << l + 1 << ' ', l = pa[l];
								cout << r + 1 << '\n';
								l = x, r = y;
								while (l != r)
									cout << l + 1 << ' ', l = pa[l];
								cout << r + 1 << '\n';
								return 0;
							}
							mp[dep[x] - dep[y]] = pi(x, y);
						}
				}
			int sz = -rt[i];
			cout << "3\n" << mp[sz - 1].first + 1 << ' ' << mp[sz - 1].second + 1 << ' ';
			if (mp[sz - 2].first == mp[sz - 1].first || mp[sz - 2].first == mp[sz - 1].second)
				cout << mp[sz - 2].second + 1 << '\n';
			else
				cout << mp[sz - 2].first + 1 << '\n';
			int l = mp[2].first, r = mp[2].second;
			while (l != r)
				cout << l + 1 << ' ', l = pa[l];
			cout << r + 1 << '\n';
			return 0;
		}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5952kb

input:

4
1 2
1 3
1 4
2 3
2 4

output:

3
3 2 1
4 2 1

result:

ok 

Test #2:

score: 0
Accepted
time: 2ms
memory: 6660kb

input:

5
1 2
1 3
1 4
1 5
2 3
2 5
3 4

output:

3
3 2 1
5 2 1

result:

ok 

Test #3:

score: 0
Accepted
time: 2ms
memory: 5884kb

input:

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

output:

4
1 2 4 3
5 6 1 2

result:

ok 

Test #4:

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

input:

40
1 16
1 40
2 4
2 16
2 36
3 25
3 38
4 1
4 13
5 11
5 27
6 4
7 5
7 11
8 10
8 14
8 24
9 34
10 20
12 35
13 2
14 10
14 20
15 18
15 28
15 31
16 6
16 13
17 5
17 11
17 27
18 9
19 1
19 4
19 16
20 24
21 12
21 33
21 35
22 38
23 12
23 21
25 28
25 31
25 34
25 38
26 14
26 20
27 7
27 11
28 3
28 31
29 16
29 19
30 ...

output:

3
7 11 5
11 5 17

result:

ok 

Test #5:

score: 0
Accepted
time: 2ms
memory: 5968kb

input:

201
1 7
1 114
1 119
2 49
2 93
4 197
5 139
6 1
6 27
7 39
7 121
8 127
9 130
9 145
11 106
11 136
11 193
12 2
12 116
13 55
13 69
13 105
13 187
13 196
14 144
14 177
15 127
15 134
15 145
15 155
15 184
15 199
16 96
16 177
17 20
21 100
22 68
22 71
22 81
22 142
23 148
23 190
24 12
24 81
24 89
25 158
25 159
2...

output:

5
15 155 57 75 197
57 75 197 4 47

result:

ok 

Test #6:

score: 0
Accepted
time: 1ms
memory: 6420kb

input:

8000
2 1508
2 3068
3 5268
3 5501
6 266
6 2737
6 3197
6 5863
6 6697
7 3492
9 427
9 794
9 3114
9 5509
10 2257
10 4348
11 1479
11 1957
11 2230
11 2500
11 3182
11 4399
11 5051
11 7727
12 7669
13 1403
13 5753
14 2871
14 6956
14 7959
15 6902
17 1630
17 3155
17 5950
18 7232
19 125
19 3280
19 5648
20 6879
2...

output:

77
112 143 195 7879 532 805 3496 114 2752 467 1167 2850 1949 4318 2357 1564 332 209 4233 461 713 880 5867 340 588 1051 1627 2904 1793 1540 3154 3249 3854 3084 283 877 1277 1149 521 5258 335 1769 1110 2451 96 872 6894 1987 1338 4778 2150 3988 5043 87 996 1184 2981 1057 5298 32 5875 1482 6651 492 5496...

result:

ok 

Test #7:

score: 0
Accepted
time: 43ms
memory: 11916kb

input:

99999
1 11261
1 21544
2 9017
2 63063
2 97990
3 11995
3 42473
4 19846
5 38099
6 35872
6 80509
7 73231
8 12356
9 35384
10 45091
12 86727
13 4938
13 48917
14 62383
14 89846
15 28458
15 44277
15 51725
15 84522
16 93258
17 13934
17 42238
18 19000
19 11278
19 23672
19 61502
19 78791
20 85057
20 88080
21 2...

output:

2575
3004 97770 30120 62151 93657 12834 32918 58548 49689 71113 97138 93478 40912 56462 53834 2637 21721 7023 17947 59298 75620 29250 28013 50477 6806 36167 96109 79939 25938 45249 74134 68088 41694 88368 45964 96410 5737 22422 45398 53895 37311 24514 33525 35809 54512 29224 41024 64464 82172 37176 ...

result:

ok 

Test #8:

score: 0
Accepted
time: 54ms
memory: 11900kb

input:

100000
1 68531
2 97359
4 68578
4 83098
4 98443
5 8053
5 30270
5 86617
6 7074
6 12266
6 69396
7 52675
7 78316
7 90757
7 92242
8 32677
8 41353
8 41457
8 74508
9 44234
10 4973
10 38390
10 96049
11 28007
11 68620
13 3016
14 36748
15 8147
15 25110
15 28489
15 72947
15 99347
16 70760
17 12774
17 68407
17 ...

output:

2955
242 1624 7746 78207 14022 37711 8889 42991 77725 64937 12132 24310 37412 59134 62344 11018 26835 21556 57622 23452 26716 38901 17895 70697 25405 72208 6767 11063 62856 3021 39419 55168 22360 77771 49113 34230 19832 80694 656 68849 15797 8691 4128 828 43014 76879 20630 24567 27369 15008 28241 47...

result:

ok 

Test #9:

score: 0
Accepted
time: 2ms
memory: 6772kb

input:

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

output:

3
7 1 6
7 6 5

result:

ok 

Test #10:

score: 0
Accepted
time: 45ms
memory: 19696kb

input:

100000
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 52
52 5...

output:

3
100000 1 99999
3 2 1

result:

ok 

Test #11:

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

input:

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

output:

3
8 1 2
8 7 6

result:

ok 

Test #12:

score: 0
Accepted
time: 2ms
memory: 7040kb

input:

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

output:

3
9 1 2
3 2 1

result:

ok 

Test #13:

score: 0
Accepted
time: 1ms
memory: 5924kb

input:

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

output:

3
10 1 9
10 9 8

result:

ok 

Test #14:

score: 0
Accepted
time: 2ms
memory: 6056kb

input:

1000
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 52
52 53
...

output:

3
1000 1 999
3 2 1

result:

ok 

Test #15:

score: 0
Accepted
time: 3ms
memory: 8316kb

input:

9999
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 52
52 53
...

output:

3
9999 1 9998
9999 9998 9997

result:

ok 

Test #16:

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

input:

10000
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 52
52 53...

output:

3
10000 1 9999
10000 9999 9998

result:

ok 

Test #17:

score: 0
Accepted
time: 42ms
memory: 19060kb

input:

94753
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 52
52 53...

output:

3
94753 1 94752
3 2 1

result:

ok 

Test #18:

score: 0
Accepted
time: 59ms
memory: 19680kb

input:

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 52
52 53...

output:

3
99999 1 2
3 2 1

result:

ok 

Test #19:

score: 0
Accepted
time: 2ms
memory: 6128kb

input:

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

output:

3
7 1 6
3 2 1

result:

ok 

Test #20:

score: 0
Accepted
time: 54ms
memory: 19700kb

input:

100000
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 52
52 5...

output:

3
100000 1 99999
3 2 1

result:

ok 

Test #21:

score: 0
Accepted
time: 2ms
memory: 7476kb

input:

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

output:

3
8 1 7
3 2 1

result:

ok 

Test #22:

score: 0
Accepted
time: 2ms
memory: 6396kb

input:

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

output:

3
9 1 8
3 2 1

result:

ok 

Test #23:

score: 0
Accepted
time: 2ms
memory: 6844kb

input:

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

output:

3
10 1 9
3 2 1

result:

ok 

Test #24:

score: 0
Accepted
time: 2ms
memory: 6056kb

input:

1000
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 52
52 53
...

output:

3
1000 1 999
3 2 1

result:

ok 

Test #25:

score: 0
Accepted
time: 3ms
memory: 7596kb

input:

9999
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 52
52 53
...

output:

3
9999 1 9998
3 2 1

result:

ok 

Test #26:

score: 0
Accepted
time: 1ms
memory: 8608kb

input:

10000
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 52
52 53...

output:

3
10000 1 9999
3 2 1

result:

ok 

Test #27:

score: 0
Accepted
time: 46ms
memory: 19772kb

input:

97065
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 52
52 53...

output:

3
97065 1 97064
3 2 1

result:

ok 

Test #28:

score: 0
Accepted
time: 58ms
memory: 19708kb

input:

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 52
52 53...

output:

3
99999 1 99998
3 2 1

result:

ok 

Test #29:

score: 0
Accepted
time: 2ms
memory: 6676kb

input:

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

output:

3
7 1 2
7 6 5

result:

ok 

Test #30:

score: 0
Accepted
time: 49ms
memory: 20080kb

input:

100000
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 52
52 5...

output:

3
100000 1 2
100000 99999 99998

result:

ok 

Test #31:

score: 0
Accepted
time: 2ms
memory: 6060kb

input:

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

output:

3
8 1 2
8 7 6

result:

ok 

Test #32:

score: 0
Accepted
time: 2ms
memory: 7092kb

input:

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

output:

3
9 1 2
9 8 7

result:

ok 

Test #33:

score: 0
Accepted
time: 2ms
memory: 6124kb

input:

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

output:

3
10 1 2
10 9 8

result:

ok 

Test #34:

score: 0
Accepted
time: 1ms
memory: 7480kb

input:

1000
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 52
52 53
...

output:

3
1000 1 2
1000 999 998

result:

ok 

Test #35:

score: 0
Accepted
time: 6ms
memory: 7792kb

input:

9999
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 52
52 53
...

output:

3
9999 1 2
9999 9998 9997

result:

ok 

Test #36:

score: 0
Accepted
time: 3ms
memory: 8040kb

input:

10000
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 52
52 53...

output:

3
10000 1 2
10000 9999 9998

result:

ok 

Test #37:

score: 0
Accepted
time: 51ms
memory: 18768kb

input:

92892
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 52
52 53...

output:

3
92892 1 2
92892 92891 92890

result:

ok 

Test #38:

score: 0
Accepted
time: 60ms
memory: 19756kb

input:

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 52
52 53...

output:

3
99999 1 2
99999 99998 99997

result:

ok 

Test #39:

score: 0
Accepted
time: 2ms
memory: 6012kb

input:

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

output:

4
2 3 7 6
8 2 3 7

result:

ok 

Test #40:

score: 0
Accepted
time: 2ms
memory: 6428kb

input:

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

output:

3
3 10 4
4 2 5

result:

ok 

Test #41:

score: 0
Accepted
time: 1ms
memory: 6444kb

input:

1000
272 271
393 394
369 404
981 980
169 185
362 361
387 386
482 481
383 382
370 788
266 106
938 223
876 877
107 106
109 110
481 480
633 14
886 885
588 589
673 567
568 693
531 932
562 561
871 872
89 959
951 950
119 556
484 891
981 271
75 74
443 444
865 730
374 15
580 233
716 165
882 829
622 623
606 ...

output:

39
6 5 4 862 863 982 983 73 112 611 848 22 689 690 691 692 693 568 569 257 432 887 696 522 389 715 873 872 871 336 302 303 317 316 822 821 820 819 7
12 74 75 438 886 272 273 274 506 507 508 509 828 118 117 398 385 386 387 986 987 856 21 20 253 142 698 98 140 141 558 559 560 561 562 563 633 14 13

result:

ok 

Test #42:

score: 0
Accepted
time: 6ms
memory: 8016kb

input:

9999
1503 1502
1862 3917
4579 4578
9929 8919
4989 4990
4479 7716
5512 5511
4389 4390
4430 910
5616 3889
5708 5879
8848 8849
5400 5076
7827 3718
1169 1168
1574 213
3196 4013
2414 2415
2857 2858
9177 9178
7189 7190
3550 3549
7446 5351
7766 8059
2132 2646
8813 7870
2521 2522
5158 5157
4623 4624
4957 49...

output:

1735
83 84 8855 8854 5023 5024 5025 5026 5027 5829 5830 53 52 51 50 49 2133 2132 2131 2130 8470 8471 1245 1246 1541 1540 1539 1538 5317 5316 5315 5314 7683 7682 8717 8718 4264 4263 4262 4261 9319 9320 9321 9322 9323 9324 6825 8439 1075 6883 6103 6104 6980 6981 6982 5811 1489 5932 5931 4173 4172 4171...

result:

ok 

Test #43:

score: 0
Accepted
time: 6ms
memory: 6960kb

input:

10000
5462 4989
4542 4541
7300 8478
4730 3574
7930 7051
750 7627
117 3045
4274 4275
3840 3841
5706 3638
7108 7107
28 29
2564 2563
2784 2393
1193 1192
2040 1286
3688 3687
8048 2319
2404 2405
8641 8640
6992 8729
5085 5086
5130 5131
6813 9806
6592 6769
2806 2805
7482 6021
7371 3994
4939 3217
1905 6540
...

output:

2693
42 41 7701 7702 7703 7995 7994 7157 7158 9668 7857 9094 6454 6453 2356 2357 2358 2359 3777 3776 3775 3193 3194 2412 2413 8305 9214 7690 7025 7024 2749 2750 2751 2582 342 341 7420 7421 7797 7796 7387 1566 8022 4140 9035 9036 522 523 4100 4101 4102 4103 4891 4892 6593 6592 1313 1314 9416 4034 403...

result:

ok 

Test #44:

score: 0
Accepted
time: 56ms
memory: 13488kb

input:

99999
49253 51314
3093 3092
88617 72981
43336 77222
65739 55450
5166 90677
57235 57234
51512 51511
73274 86124
86611 77777
21808 21809
2794 2795
64109 69571
80102 80101
56177 27689
55899 58255
16908 16909
53732 53733
9213 9214
33157 33158
10706 10707
76016 11308
51459 74662
58149 58150
80976 56845
2...

output:

10075
386 387 57618 57617 57616 65828 65827 65826 73910 73909 73908 59620 59621 59622 59623 59624 60537 60536 60535 60534 58558 78746 78745 78744 78743 37267 73564 74769 75483 75484 43081 60089 96445 24992 49980 49981 49982 68484 3590 3591 19611 74116 74117 31336 31337 31338 39720 39721 11948 42530 ...

result:

ok 

Test #45:

score: 0
Accepted
time: 59ms
memory: 13248kb

input:

96827
15894 15895
33528 48199
50450 50451
63703 63702
49937 31980
93823 45726
96052 96051
54334 16426
9193 11656
49315 10079
10614 33488
84027 84028
3612 5321
64903 64904
56901 32611
33578 68521
47938 47939
32618 53239
89613 89612
82729 82728
34512 34511
54064 38673
56419 56420
23775 75336
85989 172...

output:

25672
7 70395 31034 31033 41299 41300 41301 29403 29404 83906 74584 74585 74586 91517 4083 92418 24856 66134 66135 59560 2993 2992 2991 67195 67196 23201 23200 23199 23198 23197 23074 78358 78357 78356 86571 86570 86569 86568 86567 92058 92059 67427 67426 67425 67424 67423 67422 76796 76795 76794 76...

result:

ok 

Test #46:

score: 0
Accepted
time: 60ms
memory: 13512kb

input:

100000
72105 72104
4352 4351
59159 59160
78993 64103
39235 39234
4458 36615
23543 53027
54635 54634
80821 80822
8720 72158
49535 78364
64357 3035
93490 6597
52195 13285
70186 70187
14748 98067
15516 71738
77617 77616
68836 68835
61569 61570
28477 28289
50823 50822
71759 49859
59464 59463
83701 83702...

output:

40055
12 46017 46018 46019 46020 92184 92185 92186 80293 47730 47731 73528 73529 73530 81108 81107 81106 55986 55987 55988 55989 55990 55991 20460 13380 41114 66120 66121 61980 61981 45297 45298 45299 5919 27948 38036 77070 77069 77068 77067 77066 4937 4936 4935 4934 4933 68897 68898 91589 91588 256...

result:

ok 

Test #47:

score: 0
Accepted
time: 65ms
memory: 13528kb

input:

100000
53877 17887
7877 7878
35510 37710
15520 83926
7572 7573
11839 11840
75139 75140
63678 63679
66199 66198
3262 3263
78203 78204
87574 87575
53474 67658
86593 86594
28943 17005
71369 264
3802 41402
30583 30584
38511 38510
36776 90902
57208 57209
15408 48313
73488 46167
88419 93118
57411 57412
42...

output:

40572
13 12 11 50317 31373 31372 31371 31370 31369 6363 6362 6361 81190 99794 99793 99792 95670 95671 95672 95673 85981 85980 91900 91899 23827 23826 16306 16305 16304 35096 35097 35098 35099 17701 17700 17699 17698 71646 71647 44616 37945 37944 37943 70766 70767 70768 76740 76739 76738 40405 92396 ...

result:

ok 

Test #48:

score: 0
Accepted
time: 65ms
memory: 13604kb

input:

100000
78895 34726
20392 44705
57147 22069
31133 31132
78946 78947
53758 53757
68970 68971
75904 87094
12439 12438
92849 92848
80817 80818
76732 53635
79930 79931
78362 78363
87661 87662
47807 47808
73696 27386
30646 30645
17648 81813
47120 47119
84905 84906
87235 8058
8238 88843
86537 12191
68784 6...

output:

19903
419 420 421 96802 96803 76377 64074 61805 61804 61803 16287 16288 16289 66393 66394 66395 66396 66397 28657 28656 28655 28654 93025 74339 74338 74337 48153 35634 35633 43030 27263 27264 56300 56299 4649 4650 54864 54863 54862 54861 43544 52039 89808 89809 89810 83797 83796 83795 83794 22311 22...

result:

ok 

Test #49:

score: 0
Accepted
time: 64ms
memory: 13060kb

input:

94055
34740 73546
30256 30255
20298 20299
62592 62591
49467 49468
65041 2277
38788 38787
58735 65469
2375 2376
77665 77666
36242 80298
75550 16701
13820 64701
83448 83449
79313 83990
2213 2212
22172 22171
72441 92184
10391 30730
39194 38883
25064 90160
69140 85068
50433 31078
58353 4381
38997 38998
...

output:

26666
48 42563 42564 31525 8517 8516 8515 50814 50815 92159 92158 92157 92156 92155 51483 32429 32428 71848 71847 31020 31021 23569 41934 41935 41936 20873 20874 20875 4643 10831 23546 23547 51412 51413 91052 91051 91050 64446 64445 73713 82437 82438 82439 82440 29103 29104 29105 26587 26588 26589 2...

result:

ok 

Test #50:

score: 0
Accepted
time: 1ms
memory: 5884kb

input:

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

output:

4
3 7 6 2
5 4 3 7

result:

ok 

Test #51:

score: 0
Accepted
time: 62ms
memory: 13784kb

input:

99084
7128 52592
26282 84361
19470 70586
2431 2430
33596 72767
70001 70000
65483 65484
76493 76492
62792 39465
4476 31233
72512 72511
94244 69778
84662 84663
32214 32213
4717 4718
73918 26226
71389 71390
45765 45764
87589 87590
6207 6206
47094 70119
30908 29826
34602 40286
44413 44412
21890 21889
24...

output:

9409
378 51472 51473 67214 67215 67216 38664 20646 31789 31790 12623 12622 12621 62084 62085 62086 62087 62088 8543 8544 8526 8525 8524 8523 8522 87858 87857 87856 87855 3697 3696 41446 6489 6490 6491 83772 83773 85096 85097 85098 85099 56688 56689 52490 87008 70399 70400 70401 70402 55577 55578 681...

result:

ok 

Test #52:

score: 0
Accepted
time: 2ms
memory: 6580kb

input:

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

output:

4
4 3 2 5
7 8 4 3

result:

ok 

Test #53:

score: 0
Accepted
time: 2ms
memory: 6796kb

input:

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

output:

6
2 1 4 3 7 6
8 9 1 4 3 7

result:

ok 

Test #54:

score: 0
Accepted
time: 2ms
memory: 7344kb

input:

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

output:

5
1 2 3 4 5
3 4 5 7 6

result:

ok 

Test #55:

score: 0
Accepted
time: 2ms
memory: 6252kb

input:

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

output:

4
2 3 10 9
3 10 9 4

result:

ok 

Test #56:

score: 0
Accepted
time: 1ms
memory: 6972kb

input:

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

output:

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

result:

ok 

Test #57:

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

input:

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

output:

4
2 1 4 5
3 2 1 4

result:

ok 

Test #58:

score: 0
Accepted
time: 2ms
memory: 6144kb

input:

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

output:

4
3 1 2 4
5 6 3 1

result:

ok 

Test #59:

score: 0
Accepted
time: 1ms
memory: 7052kb

input:

4
1 2
4 1
4 3
3 1
4 2

output:

3
2 1 4
3 1 4

result:

ok 

Test #60:

score: 0
Accepted
time: 2ms
memory: 6520kb

input:

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

output:

4
4 10 8 3
5 6 9 10

result:

ok 

Test #61:

score: 0
Accepted
time: 1ms
memory: 7576kb

input:

1000
937 387
833 217
405 422
502 356
529 374
497 662
803 845
726 979
999 43
463 620
749 828
661 573
191 708
513 963
737 819
439 571
787 166
873 842
993 566
590 908
34 184
699 314
756 255
996 242
653 402
451 656
90 762
562 382
945 397
600 816
789 890
378 965
613 827
319 645
156 684
477 570
131 419
43...

output:

93
14 304 793 442 716 818 179 176 785 346 928 360 517 567 248 86 387 937 182 588 669 65 718 760 308 717 926 276 852 11 865 284 895 903 309 15 987 402 653 554 4 652 544 574 707 427 668 426 699 314 945 397 25 91 280 702 298 765 767 842 873 26 181 375 639 540 428 250 264 286 164 494 701 440 388 347 958...

result:

ok 

Test #62:

score: 0
Accepted
time: 6ms
memory: 7316kb

input:

9999
2524 8191
1533 7530
356 1008
8210 3560
2071 540
2876 4324
9158 3771
2872 5625
4701 4769
4728 2104
2264 9841
4009 2392
9900 4852
9836 1027
3996 1557
97 1319
5587 7722
7488 4073
2940 9762
246 6394
380 6935
7929 3557
8049 8841
2105 7255
2710 6626
7926 6255
8392 6949
6174 2040
9959 8955
8701 3730
5...

output:

1843
128 1443 2619 1684 227 2918 8969 5732 9651 8428 5597 1331 6413 8956 2035 8509 7340 8624 3106 7895 203 5542 4449 7352 1239 9009 2813 9384 6522 9920 8265 239 6224 5935 2923 3014 860 5049 3734 9176 3655 6489 1509 1200 5317 4078 1482 5014 7972 3155 7348 5642 6356 4381 5983 1956 1339 7886 8463 3395 ...

result:

ok 

Test #63:

score: 0
Accepted
time: 2ms
memory: 8148kb

input:

10000
8697 615
9680 5350
5924 4698
4478 7356
3510 7535
6046 3305
885 4890
8224 2297
2267 8411
7331 7035
1747 7766
3540 1409
4143 212
9541 5746
1062 539
2060 9566
5293 350
6143 2220
1446 2866
4603 4151
9625 5078
3432 4169
1528 1525
9522 2738
3154 3100
8560 9024
1200 4420
3138 9200
2346 182
1694 6303
...

output:

674
89 9138 7269 6382 5794 5405 8227 2817 8026 214 6803 6249 3415 5583 9466 5307 3810 9496 9822 9194 5490 61 1633 1895 6102 7600 5367 691 6922 8122 816 4189 2366 4465 4924 3740 7783 7339 9813 192 2139 3606 4659 9735 659 3374 4903 8585 7905 8477 1349 5303 8370 1791 9246 5743 6038 6383 8394 4173 4296 ...

result:

ok 

Test #64:

score: 0
Accepted
time: 55ms
memory: 13560kb

input:

99999
84520 53880
95569 33800
30674 78149
34453 98159
29766 87018
38710 45543
78103 64279
95388 6083
90709 6245
28076 59536
89121 25989
17455 86681
24869 49677
88947 54071
59069 14675
2211 80543
84618 24731
71749 96646
3072 81888
41124 19659
78748 83891
86353 92485
51719 3101
86489 39980
2846 67916
...

output:

6044
438 9864 52992 58883 87048 54358 34175 85145 84217 66243 2070 77937 55085 16954 15470 66278 97279 36174 64221 26172 86777 88276 74620 85553 70286 83861 70144 1147 69379 30563 15549 34932 87692 17820 42309 97174 29838 44769 41737 11172 82139 6794 44989 14074 8618 64740 50822 40920 60648 47806 11...

result:

ok 

Test #65:

score: 0
Accepted
time: 56ms
memory: 13072kb

input:

91648
4472 25803
85060 29770
38233 78885
69505 11992
74584 56733
44447 19721
38611 47816
64374 1051
85078 88959
3376 77926
30914 66149
47776 2665
24048 19740
63674 58321
31035 27289
28597 78620
26732 63968
3921 28544
88344 48945
17800 78918
39469 31300
58279 76356
88378 67190
87900 74995
96 31664
86...

output:

434
159 57942 82489 63658 87231 53343 60551 37352 37368 60275 67311 8918 30747 47987 29268 54518 61781 39654 178 66353 81818 18901 32888 52859 54254 47490 17145 36986 10834 89677 74374 58619 56264 81854 12371 71656 41681 53634 75419 39888 56886 72051 38602 84741 14893 45347 87677 57926 57711 9342 54...

result:

ok 

Test #66:

score: 0
Accepted
time: 66ms
memory: 13568kb

input:

100000
13352 1027
26975 28733
58784 97055
76806 68544
9735 23022
13365 25281
80851 10373
95287 91860
59771 31042
51912 68412
26741 29961
34375 25709
13755 46111
50736 39736
95695 18184
57397 62912
97590 59408
6754 50322
16563 80551
76371 58366
31788 49867
41825 95414
16211 24996
32999 62870
4946 820...

output:

3861
85 18855 77009 10264 2955 4581 67918 15222 26772 89925 32587 43873 3277 7011 42043 60672 84782 6636 65307 18489 37594 25718 79186 41346 65986 30018 39180 99625 57137 68191 58859 47205 9002 28799 20007 18908 880 66334 4666 29759 31015 84401 12213 10797 32458 264 19604 69495 87764 92457 69395 518...

result:

ok 

Test #67:

score: 0
Accepted
time: 59ms
memory: 13544kb

input:

100000
20959 25336
91898 62660
72720 51175
61002 85224
24094 15898
17841 75902
96298 91723
60352 50707
73566 69660
14089 5220
50982 29437
79898 86395
1734 56103
52555 46603
63369 73948
72151 60200
25210 3152
38452 28051
85173 32730
57691 99457
69691 30053
2072 97708
97968 56344
65532 44367
12342 346...

output:

28802
205 52885 49618 57215 81670 53756 17393 31352 97875 41310 42097 82891 58043 90589 78657 77500 86979 22983 80689 81957 58889 58811 11565 46679 97799 52998 19946 77858 50909 93564 1176 60444 39454 18099 13465 50013 44932 70925 54852 13121 33035 81734 97567 37175 96812 44178 77478 77371 7753 4702...

result:

ok 

Test #68:

score: 0
Accepted
time: 59ms
memory: 13700kb

input:

100000
16435 98228
89180 57831
43189 90862
16293 29922
91964 47722
34278 901
54950 37026
95302 76757
42452 74646
38280 38053
65541 27258
36041 61691
27600 40344
23817 62272
71323 52794
81547 61348
39381 11415
52865 23221
79787 93823
91146 34985
66479 79975
16439 79659
36874 49350
50891 86175
33479 5...

output:

12931
44 30613 37920 36260 56547 60618 78597 63450 59739 60612 94841 70011 51800 65833 86941 38664 32797 84638 92745 30300 84861 17537 37235 506 7844 50841 43198 59775 68591 24594 10089 92493 21370 66711 41926 49539 23109 99237 77311 59879 19608 52803 54635 67324 3947 70547 78855 57219 82256 12741 1...

result:

ok 

Test #69:

score: 0
Accepted
time: 69ms
memory: 13340kb

input:

95728
48566 69797
54999 85490
75942 40279
51954 81016
58241 2418
39067 29211
81791 12312
77375 65571
56275 38417
19545 83406
22125 73565
35590 62148
23344 55309
39501 86411
68603 19541
75927 74829
9467 14763
65439 91977
45467 52791
94490 35940
32928 3568
76229 95312
78704 76042
23090 10023
59356 602...

output:

6310
251 41973 20046 8548 6547 29221 50130 67332 26333 69622 29250 10277 72991 61772 94315 25503 24991 53234 53192 61345 45840 17706 27006 47754 53989 6247 3507 81027 79118 25691 95453 3524 21082 11173 57538 54319 15975 61146 56729 46989 71719 13168 31958 77798 7255 53367 50255 93903 77115 35858 542...

result:

ok 

Test #70:

score: 0
Accepted
time: 2ms
memory: 7032kb

input:

5
2 4
2 3
5 3
5 1
1 3
4 5
1 2

output:

4
1 2 3 5
4 2 3 5

result:

ok 

Test #71:

score: 0
Accepted
time: 59ms
memory: 13204kb

input:

93309
71437 20546
7225 87604
42872 46689
48394 70601
79628 80229
46286 21730
85596 24788
78402 13849
4309 88242
46678 82455
59146 64364
43993 73409
35381 77031
24159 45740
49493 15690
53789 31467
78790 88954
13595 76316
85033 35716
5254 44215
33086 43366
81849 23644
22197 53918
78118 73130
44242 230...

output:

18151
261 27811 1957 4078 39252 87841 143 42255 84573 53556 21606 59324 16614 84231 68437 47527 2035 31517 24466 85541 26592 43263 3808 74429 73202 58036 61234 81971 8469 89269 18802 32868 87769 64354 29812 65257 86972 92462 20684 9921 90334 47293 90095 75038 55365 8705 85698 91014 52651 90312 64352...

result:

ok 

Test #72:

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

input:

6
5 3
1 3
5 2
5 1
3 6
6 4
1 2
5 6
3 2

output:

3
2 5 3
5 3 1

result:

ok 

Test #73:

score: 0
Accepted
time: 2ms
memory: 5956kb

input:

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

output:

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

result:

ok 

Test #74:

score: 0
Accepted
time: 1ms
memory: 6340kb

input:

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

output:

3
1 5 6
3 6 7

result:

ok 

Test #75:

score: 0
Accepted
time: 2ms
memory: 6556kb

input:

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

output:

5
7 4 2 3 1
9 5 8 4 2

result:

ok 

Test #76:

score: 0
Accepted
time: 2ms
memory: 5952kb

input:

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

output:

3
4 5 6
5 6 10

result:

ok 

Test #77:

score: 0
Accepted
time: 2ms
memory: 6740kb

input:

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

output:

4
2 3 6 5
4 2 3 6

result:

ok 

Test #78:

score: 0
Accepted
time: 2ms
memory: 6984kb

input:

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

output:

6
4 10 9 8 6 3
7 10 9 8 6 3

result:

ok