QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#758492#9556. The Hanged ManguggAC ✓125ms68556kbC++203.5kb2024-11-17 18:34:592024-11-17 18:35:00

Judging History

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

  • [2024-11-17 18:35:00]
  • 评测
  • 测评结果:AC
  • 用时:125ms
  • 内存:68556kb
  • [2024-11-17 18:34:59]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <cmath>
#include <bitset>
#include <cassert>
#include <numeric>

using namespace std;
typedef long long ll;

const int N = 300010;

int n;
vector<int> edge[N];
bool f[N][2];
int g[N];
vector<pair<int, int>> e;

void dfs(int u, int father)
{
	int cnt_son = 0;
	for (int v : edge[u])
	{
		if (v == father) continue;
		cnt_son ++;
	}

	if (cnt_son & 1) f[u][1] = true;
	else f[u][0] = true;

	for (int v : edge[u])
	{
		if (v == father) continue;
		dfs(v, u);
		if (cnt_son & 1)
		{
			if (f[v][1]) f[u][0] = true, g[u] = v;
		}
		else 
		{
			if (f[v][1]) f[u][1] = true, g[u] = v;
		}
	}
}

int dfs2(int u, int st, int father)
{
	int cnt_son = 0;
	for (int v : edge[u])
	{
		if (v == father) continue;
		cnt_son ++;
	}

	if ((cnt_son & 1) && st)
	{
		vector<int> son;
		for (int v : edge[u])
		{
			if (v == father) continue;
			son.push_back(v);
		}

		for (int i = 1; i < son.size(); i += 2)
		{
			int v1 = son[i], v2 = son[i + 1];
			int s1, s2;
			if (f[v1][0]) s1 = dfs2(v1, 0, u);
			else s1 = dfs2(v1, 1, u);
			if (f[v2][0]) s2 = dfs2(v2, 0, u);
			else s2 = dfs2(v2, 1, u);
			e.push_back({s1, s2});
		}

		int v = son[0];
		if (f[v][0]) return dfs2(v, 0, u);
		else return dfs2(v, 1, u);
	}
	else if ((cnt_son & 1) && !st)
	{
		vector<int> son;
		for (int v : edge[u])
		{
			if (v == father) continue;
			if (v != g[u]) son.push_back(v);
		}

		for (int i = 0; i < son.size(); i += 2)
		{
			int v1 = son[i], v2 = son[i + 1];
			int s1, s2;
			if (f[v1][0]) s1 = dfs2(v1, 0, u);
			else s1 = dfs2(v1, 1, u);
			if (f[v2][0]) s2 = dfs2(v2, 0, u);
			else s2 = dfs2(v2, 1, u);
			e.push_back({s1, s2});
		}

		int s = dfs2(g[u], 1, u);
		e.push_back({u, s});
		return u;
	}
	else if (!(cnt_son & 1) && !st)
	{
		vector<int> son;
		for (int v : edge[u])
		{
			if (v == father) continue;
			son.push_back(v);
		}

		for (int i = 0; i < son.size(); i += 2)
		{
			int v1 = son[i], v2 = son[i + 1];
			int s1, s2;
			if (f[v1][0]) s1 = dfs2(v1, 0, u);
			else s1 = dfs2(v1, 1, u);
			if (f[v2][0]) s2 = dfs2(v2, 0, u);
			else s2 = dfs2(v2, 1, u);
			e.push_back({s1, s2});
		}

		return u;
	}
	else 
	{
		vector<int> son;
		for (int v : edge[u])
		{
			if (v == father) continue;
			if (v != g[u]) son.push_back(v);
		}

		for (int i = 1; i < son.size(); i += 2)
		{
			int v1 = son[i], v2 = son[i + 1];
			int s1, s2;
			if (f[v1][0]) s1 = dfs2(v1, 0, u);
			else s1 = dfs2(v1, 1, u);
			if (f[v2][0]) s2 = dfs2(v2, 0, u);
			else s2 = dfs2(v2, 1, u);
			e.push_back({s1, s2});
		}

		int s = dfs2(g[u], 1, u);
		e.push_back({u, s});
		
		int v = son[0];
		if (f[v][0]) return dfs2(v, 0, u);
		else return dfs2(v, 1, u);
	}
}

void solve()
{
	cin >> n;
	for (int i = 1; i <= n; i ++)
		edge[i].clear(), f[i][0] = f[i][1] = false;

	for (int i = 0; i < n - 1; i ++)
	{
		int u, v;
		cin >> u >> v;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}	

	dfs(1, 0);
	if (!f[1][0])
	{
		cout << "-1\n";
		return;
	}

	e.clear();
	dfs2(1, 0, 0);
	cout << e.size() << '\n';
	for (auto [u, v] : e)
		cout << u << ' ' << v << '\n';
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int tt = 1;
	cin >> tt;
	while (tt --)
	{
		solve();
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok Good Job! (3 test cases)

Test #2:

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

input:

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

output:

-1
-1
-1

result:

ok Good Job! (3 test cases)

Test #3:

score: 0
Accepted
time: 32ms
memory: 3776kb

input:

100000
3
1 3
2 1
3
2 3
1 2
3
2 3
1 3
3
2 1
1 3
3
1 2
2 3
3
1 3
2 3
3
2 1
1 3
3
2 3
1 2
3
2 3
1 3
3
2 1
1 3
3
2 3
1 2
3
1 3
2 3
3
1 3
2 1
3
2 3
1 2
3
2 3
1 3
3
1 3
2 1
3
1 2
2 3
3
1 3
2 3
3
2 1
1 3
3
1 2
2 3
3
1 3
2 3
3
1 3
2 1
3
2 3
1 2
3
1 3
2 3
3
1 3
2 1
3
2 3
1 2
3
1 3
2 3
3
2 1
1 3
3
2 3
1 2
3
2...

output:

1
3 2
1
1 3
1
1 2
1
2 3
1
1 3
1
1 2
1
2 3
1
1 3
1
1 2
1
2 3
1
1 3
1
1 2
1
3 2
1
1 3
1
1 2
1
3 2
1
1 3
1
1 2
1
2 3
1
1 3
1
1 2
1
3 2
1
1 3
1
1 2
1
3 2
1
1 3
1
1 2
1
2 3
1
1 3
1
1 2
1
3 2
1
1 3
1
1 2
1
3 2
1
1 3
1
1 2
1
2 3
1
1 3
1
1 2
1
3 2
1
1 3
1
1 2
1
2 3
1
1 3
1
1 2
1
2 3
1
1 3
1
1 2
1
3 2
1
1 3
...

result:

ok Good Job! (100000 test cases)

Test #4:

score: 0
Accepted
time: 28ms
memory: 3780kb

input:

75000
4
3 1
2 1
1 4
4
3 1
2 4
1 2
4
2 1
1 3
3 4
4
1 4
2 1
3 4
4
2 1
3 2
1 4
4
3 2
2 4
1 2
4
2 3
3 4
1 2
4
3 4
2 4
1 2
4
3 1
1 4
2 3
4
3 2
1 3
2 4
4
2 3
1 3
3 4
4
1 3
3 4
2 4
4
3 1
1 4
2 4
4
3 2
2 4
1 4
4
2 3
3 4
1 4
4
3 4
2 4
1 4
4
1 4
2 1
3 1
4
2 4
3 1
1 2
4
2 1
3 4
1 3
4
2 1
1 4
3 4
4
1 4
2 1
3 2
...

output:

-1
1
3 4
1
2 4
1
3 2
1
3 4
-1
1
1 4
1
1 3
1
2 4
1
1 4
-1
1
1 2
1
3 2
1
1 3
1
1 2
-1
-1
1
3 4
1
2 4
1
2 3
1
4 3
-1
1
1 4
1
1 3
1
2 4
1
1 4
-1
1
1 2
1
3 2
1
1 3
1
1 2
-1
-1
1
3 4
1
2 4
1
3 2
1
4 3
-1
1
1 4
1
1 3
1
2 4
1
1 4
-1
1
1 2
1
2 3
1
1 3
1
1 2
-1
-1
1
4 3
1
4 2
1
3 2
1
3 4
-1
1
1 4
1
1 3
1
4 2
...

result:

ok Good Job! (75000 test cases)

Test #5:

score: 0
Accepted
time: 34ms
memory: 3524kb

input:

60000
5
2 1
3 1
4 1
1 5
5
1 2
4 1
2 5
3 1
5
1 3
3 5
4 1
2 1
5
2 1
4 5
1 4
3 1
5
3 1
1 5
2 1
4 5
5
3 1
4 2
1 5
2 1
5
1 2
3 1
2 5
4 2
5
4 1
1 2
3 5
2 3
5
3 1
2 4
4 5
1 2
5
4 5
3 1
2 5
1 2
5
1 5
2 1
3 1
4 3
5
1 3
4 1
2 5
3 2
5
4 3
2 1
1 3
3 5
5
3 4
1 3
4 5
2 1
5
2 1
1 3
4 5
3 5
5
3 4
4 1
1 5
2 1
5
3 1
...

output:

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

result:

ok Good Job! (60000 test cases)

Test #6:

score: 0
Accepted
time: 29ms
memory: 3636kb

input:

50000
6
1 6
5 1
4 1
2 1
3 1
6
5 1
3 1
1 2
2 6
4 1
6
4 1
5 1
1 3
2 1
3 6
6
4 6
2 1
5 1
3 1
1 4
6
5 6
1 5
4 1
3 1
2 1
6
4 1
5 6
2 1
1 6
3 1
6
1 6
3 1
2 1
5 2
4 1
6
3 1
5 2
1 2
2 6
4 1
6
4 1
2 3
5 1
1 2
3 6
6
4 6
1 2
3 1
2 4
5 1
6
1 2
5 6
2 5
3 1
4 1
6
1 2
2 6
4 1
3 1
5 6
6
5 3
3 1
1 6
2 1
4 1
6
5 1
3 ...

output:

-1
2
5 3
6 4
2
4 5
6 2
2
2 5
3 6
2
6 4
3 2
2
4 2
5 3
2
6 3
5 4
-1
2
4 5
1 6
2
3 5
1 6
2
3 4
1 6
2
4 3
1 5
2
5 6
2 4
2
5 4
1 6
-1
2
2 5
1 6
2
2 4
1 6
2
4 2
1 5
2
3 5
6 2
2
3 5
1 6
2
2 5
1 6
-1
2
2 3
1 6
2
2 3
1 5
2
4 3
2 6
2
3 4
1 6
2
4 2
1 6
2
2 3
1 6
-1
2
3 2
1 4
2
4 3
5 2
2
4 3
1 5
2
2 4
1 5
2
3 2...

result:

ok Good Job! (50000 test cases)

Test #7:

score: 0
Accepted
time: 31ms
memory: 3812kb

input:

42857
7
3 1
2 1
5 1
6 1
4 1
1 7
7
4 1
1 2
6 1
3 1
2 7
5 1
7
3 7
2 1
1 3
4 1
6 1
5 1
7
4 7
1 4
6 1
5 1
2 1
3 1
7
4 1
1 5
6 1
3 1
5 7
2 1
7
6 7
5 1
2 1
4 1
1 6
3 1
7
6 7
2 1
1 7
3 1
5 1
4 1
7
4 1
5 1
6 2
3 1
2 1
1 7
7
1 2
4 1
6 2
3 1
2 7
5 1
7
6 1
2 3
4 1
5 1
1 2
3 7
7
6 1
4 7
3 1
1 2
5 1
2 4
7
1 2
3 ...

output:

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

result:

ok Good Job! (42857 test cases)

Test #8:

score: 0
Accepted
time: 36ms
memory: 3808kb

input:

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

output:

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

result:

ok Good Job! (37500 test cases)

Test #9:

score: 0
Accepted
time: 22ms
memory: 3964kb

input:

300
1000
815 567
883 63
783 506
485 779
142 248
218 214
617 238
481 567
20 203
119 212
953 179
44 830
427 156
97 916
763 172
484 512
916 21
417 958
408 257
238 634
891 213
90 208
394 56
758 819
435 26
636 718
880 212
458 662
123 212
239 156
548 314
852 436
722 828
271 429
493 27
910 421
354 143
956 ...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok Good Job! (300 test cases)

Test #10:

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

input:

3
100000
21854 12448
41900 78683
26279 40303
96957 78925
50096 72644
14704 14585
44195 23551
3290 42026
25017 64658
4593 10713
29129 13530
62892 43675
23793 13329
97502 10091
78766 44620
59301 95815
25781 93162
12231 24059
77637 66545
53889 84545
65596 58277
31337 87701
29049 43837
99301 2408
41562 ...

output:

-1
-1
-1

result:

ok Good Job! (3 test cases)

Test #11:

score: 0
Accepted
time: 70ms
memory: 21224kb

input:

1
300000
264872 86229
63995 164384
180167 260692
169708 168083
149321 50390
177160 60629
178607 170744
176734 60911
231963 17936
49668 90468
205798 261858
7645 12727
240590 1798
8446 139678
32309 208096
226620 119112
204528 63548
110330 250899
219366 144880
258130 23221
203423 40874
45194 78650
1571...

output:

-1

result:

ok Good Job! (1 test case)

Test #12:

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

input:

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

output:

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

result:

ok Good Job! (30000 test cases)

Test #13:

score: 0
Accepted
time: 40ms
memory: 3656kb

input:

3000
99
79 72
72 6
1 90
94 89
31 28
59 89
78 85
73 35
57 45
45 99
38 57
11 70
26 14
92 13
35 52
30 18
61 15
29 86
60 22
5 57
17 84
36 84
70 37
10 86
80 91
34 87
65 8
42 88
87 25
88 43
8 47
33 78
62 47
15 73
83 77
24 33
97 38
23 77
20 34
85 32
55 22
63 10
66 30
39 5
28 62
89 15
37 49
16 75
74 66
47 4...

output:

46
45 67
60 55
22 16
34 27
25 34
26 25
76 14
5 58
97 5
2 57
4 2
3 93
6 79
80 6
71 19
65 71
62 48
8 62
50 9
17 36
74 84
66 40
66 51
52 30
94 59
61 89
15 81
35 15
29 35
29 7
86 63
69 82
37 11
78 37
24 41
85 33
83 23
32 77
86 32
46 47
56 46
53 44
95 43
13 88
12 13
1 12
43
34 71
26 62
59 25
13 29
45 88
...

result:

ok Good Job! (3000 test cases)

Test #14:

score: 0
Accepted
time: 91ms
memory: 10016kb

input:

3
100000
83890 7467
75295 89651
4062 83955
60269 26734
58357 54437
22200 48174
87338 74094
86583 7977
1136 84701
34461 47665
82355 28324
32412 16170
5270 73823
37181 86410
22445 59139
27816 47294
540 79932
73768 41579
14577 92388
31765 75494
49018 24756
57215 90140
86438 22430
3974 15829
59053 22856...

output:

45450
69462 14972
60361 69462
60361 84289
59467 16458
53267 50266
29909 28352
1482 64339
73850 63766
98874 73850
88970 93604
55319 79911
13965 4339
48076 13965
75108 41126
92739 75108
33305 8247
5880 27868
64816 30434
77651 64816
23833 77651
46359 81951
11125 46359
99591 84782
2188 12048
16672 2188
...

result:

ok Good Job! (3 test cases)

Test #15:

score: 0
Accepted
time: 112ms
memory: 23576kb

input:

1
300000
30683 45175
202516 82288
209967 151196
160370 148366
36159 83057
277846 18399
58641 259342
220025 290125
299864 69137
276256 59853
163412 98854
211643 219357
45085 203080
17046 259484
175009 201826
220413 253746
280406 235850
107084 114346
6196 164024
149354 242637
8884 201047
102007 121900...

output:

136438
226276 227014
244586 40395
150593 178221
104057 155066
52177 24604
7234 52781
117858 40404
276942 189264
274126 155823
274126 55852
41813 36453
113901 41813
235846 158376
274314 180113
93781 274314
68766 11278
213782 46817
236304 101700
84358 102702
152777 81977
16117 143603
271588 16117
2715...

result:

ok Good Job! (1 test case)

Test #16:

score: 0
Accepted
time: 124ms
memory: 68556kb

input:

1
300000
98923 244101
265083 199522
178854 130825
233559 275176
51110 162632
100454 144508
203138 94733
112144 116959
221684 184011
122356 174675
240265 56410
83529 213874
174757 59833
87918 98194
231431 71105
145121 105056
205429 60598
114418 168280
249115 124674
160102 183789
27460 854
72909 12628...

output:

149999
282235 250509
79377 282235
7803 79377
163185 7803
237928 163185
126395 237928
216252 126395
45065 216252
70103 45065
159963 70103
279383 159963
66689 279383
248398 66689
139570 248398
181061 139570
256780 181061
157191 256780
212942 157191
107414 212942
113706 107414
166170 113706
222015 1661...

result:

ok Good Job! (1 test case)

Test #17:

score: 0
Accepted
time: 114ms
memory: 23728kb

input:

1
300000
51552 258960
174014 1763
298103 122466
80039 102474
90881 123355
37816 182571
209856 199049
68745 246931
231305 147333
256217 77569
277988 49579
174054 154053
74959 60605
281490 278569
131850 7894
138112 208044
207380 67110
1334 204240
117581 152706
90835 142455
54402 68306
264004 244539
99...

output:

136389
275851 284066
200764 266297
153856 83772
31091 203834
113538 157030
272657 131551
108296 252281
4471 268062
15054 201161
209490 32542
222048 191215
9136 45120
16713 288334
96888 252824
148899 145563
148899 101865
200439 35225
200439 212754
244628 17762
218749 190990
113323 221710
55041 113323...

result:

ok Good Job! (1 test case)

Test #18:

score: 0
Accepted
time: 88ms
memory: 10016kb

input:

3
100000
43104 39350
58310 72159
1910 78304
366 33335
3494 5822
948 92660
11882 15212
69203 4346
45739 21275
65867 55409
61694 88089
71479 40349
35887 88786
52148 61962
82180 65178
93823 47701
43116 75915
86963 34539
50583 74229
40562 91601
12139 88394
52559 57679
25481 60170
31207 85832
4201 92027
...

output:

45446
34174 37602
67200 2175
50688 20481
98154 72262
54685 49231
29453 54685
22751 29453
96536 42824
47425 96536
65889 36864
31013 19280
43698 52950
92943 96312
59423 92943
97834 47883
72398 87690
99605 15669
33274 23492
71031 36220
25301 30164
23405 25301
18142 4963
76033 10380
19720 27407
49199 55...

result:

ok Good Job! (3 test cases)

Test #19:

score: 0
Accepted
time: 125ms
memory: 67172kb

input:

1
299999
153306 123584
100430 137396
151712 125355
180598 178628
178522 156317
6811 124889
41530 107031
35237 104587
235884 157908
130785 274651
141969 58315
203297 225663
192833 74643
223470 99863
272704 178999
163551 250862
133718 39962
199271 24737
159107 66084
139074 91207
229404 47856
273704 12...

output:

149999
42721 211007
238901 42721
166398 238901
132405 166398
104873 132405
231355 104873
270603 231355
223096 270603
220115 223096
145808 220115
292994 145808
183310 292994
251757 183310
296895 251757
232914 296895
180602 232914
235879 180602
55611 235879
174343 55611
229539 174343
107960 229539
412...

result:

ok Good Job! (1 test case)

Test #20:

score: 0
Accepted
time: 35ms
memory: 3856kb

input:

3000
100
9 37
30 16
87 75
66 20
89 79
78 72
48 5
62 100
61 95
69 93
23 86
18 48
32 24
91 43
54 93
92 63
15 7
6 92
67 35
65 89
8 26
21 98
1 65
40 85
36 41
77 39
56 44
69 70
46 67
80 60
94 96
14 36
34 99
84 62
22 74
23 79
46 19
27 51
11 14
18 70
85 8
73 6
97 40
71 83
41 98
61 87
2 90
45 5
20 44
17 81
...

output:

49
58 2
86 58
79 86
65 79
49 25
43 49
66 43
44 66
3 44
11 3
36 11
98 36
96 98
72 96
50 72
47 50
16 47
27 16
33 27
54 33
69 54
18 69
5 18
71 5
34 71
26 34
85 26
97 85
60 97
7 60
77 7
74 77
12 74
84 12
100 84
76 100
81 76
92 81
73 92
95 73
87 95
24 87
53 24
4 53
19 4
67 19
10 67
9 10
65 9
49
87 82
83 ...

result:

ok Good Job! (3000 test cases)

Test #21:

score: 0
Accepted
time: 117ms
memory: 45556kb

input:

1
299999
123584 153306
137396 100430
114758 125355
180598 13155
156317 178522
124889 6811
41530 27377
104587 35237
157908 235884
130785 44576
141969 129416
225663 203297
120350 74643
20300 99863
295855 178999
198163 250862
133718 148059
24737 199271
66084 159107
91207 139074
229404 89529
273704 1565...

output:

149999
211007 37266
200879 11999
42721 60007
186847 27264
238901 168918
104377 128434
16950 166398
32487 54607
132405 36096
56533 259128
54072 104873
278891 248224
231355 51169
272859 6029
269039 270603
152728 274636
223096 212267
267911 21399
8757 220115
124154 44070
51060 145808
56725 235148
27976...

result:

ok Good Job! (1 test case)

Test #22:

score: 0
Accepted
time: 74ms
memory: 8200kb

input:

10
29999
29014 14470
26823 2725
13020 1832
9002 521
22160 26983
2964 2174
20830 22020
19201 4850
19060 10457
23936 2163
22700 29072
28735 4318
15942 8678
10533 9761
8946 29013
12121 555
14303 26560
18146 20485
16984 345
22717 347
21795 27399
20125 489
6200 24303
21419 17994
28274 28769
28326 25399
1...

output:

14999
23907 28453
2920 15770
10326 4578
27593 24984
21879 1186
23588 8661
22099 6245
11850 26588
27395 27247
10476 753
12794 18957
22591 15447
17765 22536
19499 17275
16647 445
27680 25765
16086 16011
13029 28687
22326 2733
8253 1258
8517 18060
19084 14385
3375 1407
10732 19322
26691 12939
2893 1455...

result:

ok Good Job! (10 test cases)

Test #23:

score: 0
Accepted
time: 90ms
memory: 23816kb

input:

1
299999
258553 127891
200368 10642
134395 33327
66807 64283
298570 239432
106569 74919
101275 256095
215172 160205
258907 145255
294970 120844
120747 17359
231598 191111
103394 179995
276483 13575
153143 236649
32255 165538
13973 180565
114480 173795
280161 260850
239991 6207
137809 102438
160694 2...

output:

149999
111723 913
250383 54231
14505 6273
63344 192141
19533 245742
102767 92054
19673 146995
170199 153965
193920 59290
170634 31337
115685 114117
229707 42148
241411 214915
128661 250675
89866 275451
118436 136421
103172 263583
108432 129950
87792 61736
110759 12817
39294 97418
40128 150702
23313 ...

result:

ok Good Job! (1 test case)

Test #24:

score: 0
Accepted
time: 63ms
memory: 6216kb

input:

10
29999
21547 280
5396 29060
21129 24483
1948 5302
5994 20221
12679 20525
23088 2218
24614 17646
9854 7760
23220 29541
9824 25475
9144 8680
17400 22930
3583 13702
14210 16949
4145 4827
4927 15200
5195 13939
23998 23812
20779 22916
19383 23442
29184 11705
12676 19405
4120 11612
24747 1107
25087 1775...

output:

14999
24835 18492
5402 1261
2326 27527
21589 4762
20303 20380
28716 20243
23708 27537
5733 26751
8459 13322
6847 20968
22566 15645
1239 2740
11193 7393
19607 7625
8697 24423
22386 16672
13638 10934
290 9410
24183 1189
18619 25500
17040 16099
10164 14964
14431 6139
9254 25639
13305 1687
18617 25064
8...

result:

ok Good Job! (10 test cases)

Test #25:

score: 0
Accepted
time: 40ms
memory: 3612kb

input:

27000
11
3 5
11 3
2 3
7 1
10 8
8 6
9 8
3 1
8 4
1 8
11
3 1
1 2
5 6
11 1
6 9
10 6
4 8
1 5
1 7
5 8
11
1 3
6 11
4 6
10 1
1 8
2 6
7 11
1 9
11 1
6 5
11
3 7
6 8
11 3
9 6
3 8
6 4
1 8
5 9
10 3
2 9
11
8 5
6 8
11 5
8 2
7 11
4 5
8 9
3 10
3 11
8 1
11
7 3
2 3
9 1
8 10
8 1
9 5
3 9
4 1
6 8
11 3
11
8 5
8 1
6 8
11 8
...

output:

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

result:

ok Good Job! (27000 test cases)

Test #26:

score: 0
Accepted
time: 39ms
memory: 3560kb

input:

30000
6
5 3
6 2
4 1
1 3
2 1
4
4 2
1 4
1 3
11
9 1
10 11
11 3
11 9
4 6
3 7
2 11
1 6
1 5
8 9
17
6 15
10 7
8 17
13 11
3 8
15 4
16 3
12 4
15 10
2 6
6 9
5 13
5 14
2 1
10 5
8 15
14
14 5
1 6
12 4
8 14
5 9
13 5
4 9
1 13
7 13
5 3
11 14
5 10
2 13
12
3 6
5 1
8 3
12 2
12 7
5 4
9 4
11 10
6 12
12 5
4 11
17
15 11
1...

output:

2
4 5
1 6
1
2 3
5
10 2
11 7
11 8
9 5
1 4
7
11 14
7 5
12 10
8 16
15 17
15 9
1 6
6
7 2
3 10
5 12
8 11
13 14
6 13
5
6 8
7 6
5 2
9 10
1 4
7
2 13
16 9
11 3
4 12
16 10
7 8
1 14
6
2 11
7 9
6 12
6 10
3 4
1 5
-1
2
5 4
1 3
5
3 8
7 4
11 6
5 2
9 5
4
10 2
9 3
4 5
1 4
5
11 3
2 6
7 13
9 10
9 8
4
6 10
8 9
8 2
1 3
1...

result:

ok Good Job! (30000 test cases)

Test #27:

score: 0
Accepted
time: 88ms
memory: 19900kb

input:

1
253253
50359 179100
159762 56963
156480 129546
194694 165531
171829 15612
8904 244239
167203 79755
59278 193676
6064 179420
93089 11873
208865 161063
72803 55831
6938 69443
182632 252034
15492 123140
26694 88239
59982 95642
209852 233064
205527 137224
222851 93508
28102 71250
250703 159154
54445 3...

output:

111343
221471 206351
223950 180757
116462 75226
55050 122548
119613 34283
83695 101748
32686 123618
45588 14301
45588 150358
194434 116466
64851 103725
55223 216887
238386 218833
115392 238386
146850 46252
192488 146850
221177 157290
31025 81722
123017 59820
159333 252795
20039 252162
74116 221939
1...

result:

ok Good Job! (1 test case)

Test #28:

score: 0
Accepted
time: 48ms
memory: 3796kb

input:

300
1855
1007 450
4 615
1845 844
426 65
1135 79
1020 1386
935 343
936 16
219 1370
1495 131
1409 13
1087 31
63 804
145 1689
1750 1731
694 623
243 626
418 1383
1396 990
1234 385
867 969
779 337
615 732
657 286
1134 1651
269 582
903 1755
478 1384
1360 1060
144 1082
217 1537
185 61
1634 1813
313 876
879...

output:

819
350 839
1837 1501
349 446
708 1102
746 764
1725 263
1790 1183
934 1790
1184 600
418 1451
1383 1672
331 968
1725 977
668 1760
1705 143
898 1613
1527 898
1527 870
1711 139
539 486
545 1201
1711 1066
503 927
79 453
101 29
131 361
79 131
1289 603
910 316
910 1228
745 1848
529 213
997 710
634 1836
56...

result:

ok Good Job! (300 test cases)

Test #29:

score: 0
Accepted
time: 79ms
memory: 22952kb

input:

1
297722
2542 280838
47066 211579
45334 161254
161254 3387
161254 81700
286925 161254
188708 161254
163323 239454
177641 142518
161254 141588
161254 289112
161254 132883
161254 264103
161254 7898
131553 35341
274424 85972
161254 111454
161254 245526
195088 87188
83391 252892
74347 144981
248942 2949...

output:

129025
45334 227606
45334 3387
81700 9424
172169 2411
286925 172169
81700 286925
141588 17961
66446 141588
289112 43895
289112 132883
264103 114802
264103 27124
245526 189672
77408 245526
270644 68163
91650 78091
96680 91650
220281 22471
96680 220281
20436 16736
246556 19890
276842 105669
236659 276...

result:

ok Good Job! (1 test case)

Test #30:

score: 0
Accepted
time: 88ms
memory: 23872kb

input:

1
297687
114063 114325
61315 256781
17004 254276
279378 173674
50685 133866
254276 270764
254276 168958
160573 254276
183000 144763
254276 41646
138547 226105
254276 62934
250757 284583
254276 147160
254276 62486
163839 23030
246684 80048
219153 38897
254276 184254
297273 295022
146005 254276
229491...

output:

124001
270764 168958
160573 102396
160573 41646
147160 236361
62934 147160
62486 294131
62486 184254
146005 229491
145456 284465
29159 84360
252959 29159
101489 18377
106304 181740
101489 106304
221679 153762
26858 21780
26858 143098
165032 176765
165032 196416
104644 136377
59069 125274
269274 1418...

result:

ok Good Job! (1 test case)

Test #31:

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

input:

1
298467
24310 131068
270342 284416
110818 163791
140749 270342
200509 156894
128257 270342
286273 39457
230236 150598
48559 18558
271934 270342
270342 221456
270342 240611
146171 270342
142089 270342
265273 37099
4824 207615
273677 270342
270342 233942
131877 270342
282024 14594
58550 270342
3225 1...

output:

99501
284416 47296
45750 271934
258911 4274
146171 285233
44790 233942
69725 58550
101680 101481
112868 247170
291074 214678
71298 189495
67846 98283
75457 289069
249713 13857
179285 103082
239658 37727
54663 91537
178634 191408
151382 294260
19474 112683
268830 75834
94392 56469
33154 284071
209627...

result:

ok Good Job! (1 test case)

Test #32:

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

input:

1
299096
43798 64829
64829 22308
25723 64829
125491 64829
132554 64829
64829 31091
82698 64829
161922 64829
64829 48363
153172 64829
198568 64829
64829 68075
246874 64829
64829 122620
64829 237999
64829 257438
44676 64829
64829 295759
64829 45750
64829 17755
195879 64829
86788 64829
172696 64829
648...

output:

-1

result:

ok Good Job! (1 test case)

Test #33:

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

input:

1
299097
55978 208819
55978 222666
55978 118386
176498 55978
177724 55978
55978 286400
7823 55978
55978 86011
258404 55978
55978 127466
55978 52857
34668 55978
31665 55978
55978 160320
55978 239002
290038 55978
55978 36827
55978 280050
55978 104777
55978 158847
52282 55978
206198 55978
55978 58412
1...

output:

149548
222666 118386
176498 177724
286400 7823
86011 258404
127466 52857
34668 31665
160320 239002
290038 36827
280050 104777
158847 52282
206198 58412
158676 106284
130153 262744
83730 87284
98968 282354
295978 172986
247495 193012
69851 279835
169064 160705
58450 284089
16418 92496
263605 54526
27...

result:

ok Good Job! (1 test case)

Test #34:

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

input:

1
299097
166438 82625
82625 128838
82625 141580
83485 82625
82625 210941
82625 40444
82625 45514
112980 82625
82625 8971
82625 240680
53717 82625
82625 243508
275918 82625
82625 214884
80291 82625
82625 244056
278345 82625
82625 50552
82625 84626
234287 82625
227857 82625
82625 282783
82625 169441
1...

output:

149548
128838 141580
83485 210941
40444 45514
112980 8971
240680 53717
243508 275918
214884 80291
244056 278345
50552 84626
234287 227857
282783 169441
1413 143280
191958 153073
141476 148589
252875 85463
224039 269930
282876 282912
36413 6466
55929 73964
181852 1058
184784 149551
137909 201141
5553...

result:

ok Good Job! (1 test case)

Test #35:

score: 0
Accepted
time: 73ms
memory: 25440kb

input:

1
299097
260330 58892
133029 58892
58892 172471
42729 58892
58892 26074
58892 99490
58892 3974
59464 58892
58892 186328
119256 58892
225649 58892
162394 58892
58892 128284
58892 215895
281775 58892
275533 58892
58892 149488
167782 58892
22771 58892
58892 63000
58892 9677
83128 58892
58892 121018
588...

output:

149548
133029 172471
42729 26074
99490 3974
59464 186328
119256 225649
162394 128284
215895 281775
275533 149488
167782 22771
63000 9677
83128 121018
288822 66044
112020 277110
260473 68644
35006 99291
127209 200917
130518 235295
210701 57873
11396 249308
195229 159762
286320 120559
169660 289468
23...

result:

ok Good Job! (1 test case)

Test #36:

score: 0
Accepted
time: 61ms
memory: 5804kb

input:

10
29462
10852 16001
15495 6444
21756 23481
23752 13053
21560 13691
9711 23194
24917 23476
13053 18916
5 8995
17585 23447
644 13053
27831 13053
22383 10656
15443 21538
10814 3308
4868 2089
23555 13053
25895 13053
12345 13893
13053 14041
13053 8611
4444 15324
23999 27186
27037 13053
23208 22273
22940...

output:

12753
12215 1154
27831 29434
25024 5306
23555 25024
27831 23555
4918 15569
14041 4918
3021 14041
27037 10580
8611 27037
25046 1191
25046 14277
22693 6190
10665 22693
8638 10665
14913 29185
19036 14913
7158 19036
1479 12010
1997 1479
7081 25806
20435 7081
1997 20435
20755 4753
8154 22528
20755 8154
1...

result:

ok Good Job! (10 test cases)

Test #37:

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

input:

100
2959
1769 2187
2304 2429
2635 1931
271 2342
1671 153
707 1154
2597 1668
1048 204
1242 1301
926 2013
1557 2752
488 1893
613 1809
1416 2395
120 1179
982 321
2686 86
2313 2009
878 848
1447 2207
728 1885
2812 1683
1290 1627
2701 135
933 1099
1719 393
2355 2519
1368 384
311 1080
823 1642
459 2670
266...

output:

1456
1387 1882
2656 1387
2218 2656
1535 2218
706 1535
1124 706
518 1124
2138 518
1519 2138
2118 1519
1993 2118
890 1993
2616 890
2459 2616
2954 2459
2189 2954
2322 2189
1843 2322
47 1843
1108 47
1267 1108
2509 1267
2215 2509
1610 2215
2629 1610
1611 2629
1796 1611
2816 1884
77 2816
2620 77
562 2620
...

result:

ok Good Job! (100 test cases)

Test #38:

score: 0
Accepted
time: 40ms
memory: 3720kb

input:

1000
294
200 192
200 46
43 256
85 47
98 12
127 200
111 127
257 124
168 32
45 274
197 49
200 27
144 38
156 256
148 202
200 80
31 248
35 66
282 128
60 200
189 37
88 54
238 280
44 245
46 263
220 53
144 200
200 55
58 184
200 153
84 173
31 284
24 170
200 211
22 244
232 242
200 208
188 26
139 154
251 104
...

output:

127
175 188
127 102
263 127
66 292
27 66
80 72
27 80
60 246
250 158
144 250
60 144
55 265
153 201
55 153
48 208
110 78
179 110
178 124
179 178
99 44
107 118
99 107
236 7
236 2
28 240
75 34
28 75
146 224
237 89
194 237
146 194
242 191
12 11
172 12
126 8
29 126
258 29
162 16
162 125
69 182
196 13
109 ...

result:

ok Good Job! (1000 test cases)

Test #39:

score: 0
Accepted
time: 93ms
memory: 24140kb

input:

1
299997
253129 238438
256990 147794
56683 265606
62100 74831
58006 231602
227120 138613
72936 16010
271383 221839
110579 31739
13864 11106
196180 159069
78858 61661
262511 279235
45738 172410
2512 6066
144552 29625
194524 184023
196218 229474
256817 33532
166763 175023
188106 91596
93278 158818
280...

output:

149998
196881 190578
184037 75643
63226 194586
110273 71152
79335 267591
10054 86395
57023 203096
276620 193642
71691 134359
251281 278053
297322 39969
184566 133418
251365 208358
53439 60588
63235 105226
98374 100699
87173 35047
206875 17905
115667 229308
207858 15789
109479 159917
235737 213210
26...

result:

ok Good Job! (1 test case)

Test #40:

score: 0
Accepted
time: 103ms
memory: 24016kb

input:

1
299995
251405 13382
21412 273614
170998 239060
142811 89087
163686 80590
54073 23173
29717 93866
155059 150414
171846 663
218307 10405
252692 83378
131202 289721
52385 252854
293096 280491
216796 237285
242784 243233
52784 6922
68312 26488
205497 147202
65036 297840
58601 67107
164525 57839
167843...

output:

149997
268237 17641
247634 58438
220519 125708
72506 180828
157593 222385
126396 245628
19020 162463
275579 66911
29461 242570
148639 124276
207502 76765
208819 292318
293356 74228
273127 109573
209809 139574
155956 86925
182839 212830
226068 143344
173403 29945
77556 223571
36468 33961
53070 48177
...

result:

ok Good Job! (1 test case)

Test #41:

score: 0
Accepted
time: 96ms
memory: 23692kb

input:

1
299993
5467 110867
249637 87281
209055 74176
170317 272027
19928 97403
158898 19368
120942 93881
150886 63314
221175 188504
125295 79790
241291 263489
258417 196595
157362 130040
163372 85682
261036 45856
257946 163512
54262 17552
251249 14029
213457 65927
265238 36030
4861 71772
159755 111439
375...

output:

149996
260002 133472
201067 46797
142667 126576
15002 154521
166926 216021
191213 18475
74814 162952
250950 133829
232481 78775
179062 184439
283567 256071
181229 24848
42560 158648
276429 214024
87898 72314
44933 251524
145314 281494
293187 19916
244930 194128
204580 80630
18920 140952
46232 129840...

result:

ok Good Job! (1 test case)

Test #42:

score: 0
Accepted
time: 107ms
memory: 23544kb

input:

1
299991
248982 174625
105559 244297
35265 128781
206509 158409
13863 41023
249166 59270
215265 188850
218206 113138
126624 205065
241101 283870
31511 34427
237845 182965
134293 221193
214509 104965
67564 158810
198261 216053
115921 200242
245392 107170
62619 285117
48060 132083
166094 84748
150023 ...

output:

149995
217984 256558
270275 111200
260888 235592
68608 100909
163358 17785
293359 21778
115930 227677
45797 20192
4685 238334
237911 298718
805 235848
63387 83460
81025 282673
241872 76933
33178 167575
101756 184489
208278 91584
120786 242332
241799 145921
117744 53206
290635 89316
170439 913
113473...

result:

ok Good Job! (1 test case)

Test #43:

score: 0
Accepted
time: 99ms
memory: 22252kb

input:

1
299999
185541 176688
252501 252009
201515 181336
174664 10052
235206 78841
271650 240453
177704 41444
30343 236755
136584 224074
123830 176470
119252 294416
176341 111829
241834 52983
35945 184402
68227 225761
146133 151540
249663 70136
156441 42951
95322 152829
259090 103376
84766 152588
150129 1...

output:

149999
75245 142906
95233 122303
45046 153060
193493 117602
32338 17247
211498 186582
241655 226346
114069 84873
152881 10358
288910 224102
62350 33081
174995 90924
80447 18922
27631 153350
7568 36264
93731 31832
164252 72117
168516 173015
188645 195361
198645 56082
47951 45055
161787 73469
126204 5...

result:

ok Good Job! (1 test case)

Test #44:

score: 0
Accepted
time: 106ms
memory: 22312kb

input:

1
299997
46586 268160
120257 162918
155586 87070
233774 236522
195573 139640
213343 184602
26338 174317
236326 103114
246267 241694
166020 217647
73806 217138
115817 291894
296219 281396
231138 217264
57086 215561
296205 295067
174916 36910
262907 177629
268640 277927
33944 172724
299448 298104
2913...

output:

149998
39530 84575
80080 88714
69999 209545
166622 211693
84267 22177
186371 16610
211376 128330
143689 103785
245172 171948
245907 256383
82310 6102
59035 28542
203536 73245
174853 218947
64029 137430
81131 179384
207040 14928
256003 243087
265540 270356
2172 113814
78112 39153
109154 112518
231532...

result:

ok Good Job! (1 test case)

Test #45:

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

input:

100
2997
1842 108
983 1626
2076 2280
1960 2673
2029 1154
1506 836
144 1843
173 1775
322 1567
1632 1092
2608 2819
2737 2888
24 2046
400 2487
2396 2569
2072 1695
2223 2237
2175 592
694 2236
2523 2322
2211 2325
2196 2888
1509 1586
2376 2272
2063 2310
2471 2612
2530 2101
1618 25
1830 1404
2646 743
2256 ...

output:

1498
857 291
1354 1597
623 943
2035 1865
871 1199
1628 1010
1072 1478
1691 2084
2687 2442
1396 467
1746 1325
151 2350
2840 2638
108 1255
1842 571
1467 1318
1635 1133
926 1723
1077 1766
1774 1141
210 965
778 472
509 2077
2162 1015
2392 2222
1114 2498
1230 1089
2520 2663
2624 2695
2733 665
2066 2754
8...

result:

ok Good Job! (100 test cases)

Extra Test:

score: 0
Extra Test Passed