QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#137955#1884. Mission Impossible: Grand Theft AutozhaohaikunAC ✓146ms48404kbC++147.0kb2023-08-10 19:43:032023-08-10 19:43:06

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 19:43:06]
  • 评测
  • 测评结果:AC
  • 用时:146ms
  • 内存:48404kb
  • [2023-08-10 19:43:03]
  • 提交

answer

#include <bits/stdc++.h>
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
const int N = 2e5 + 10;
int n, tot, dfn[N], rdfn[N], s[N], ff[N], t[N];
vector <int> v[N];
set <int> vv[N];
void dfs(int x, int fa) {
	// cout << "# " << x << " " << v[x].size() << endl;
	ff[x] = fa;
	if (v[x].size() == 1) t[dfn[x] = ++tot] = x;
	else dfn[x] = tot + 1;
	for (int i: v[x])
		if (i != fa) dfs(i, x);
	rdfn[x] = tot;
}
void zhk() {
	tot = 0;
	read(n);
	F(i, 1, n) s[i] = 0, v[i].clear(), vv[i].clear();
	// cout << "N: " << n << endl;
	F(i, 1, n - 1) {
		int x, y; read(x), read(y);
		// cout << x << " " << y << endl;
		vv[x].insert(y);
		vv[y].insert(x);
	}
	if (n == 2) {
		puts("YES\n1 2\n1 2");
		return;
	}
	while (true) {
		bool flag = true;
		F(i, 1, n) {
			if (vv[i].size() == 2) {
				// cout << "!! " << i << endl;
				flag = false;
				int a = *vv[i].begin(), b = *vv[i].rbegin();
				vv[a].erase(i);
				vv[b].erase(i);
				vv[i].clear();
				vv[a].insert(b);
				vv[b].insert(a);
			}
		}
		if (flag) break;
	}
	F(i, 1, n)
		for (int j: vv[i])
			v[i].push_back(j);
	int rt = -1;
	F(i, 1, n)
		if (v[i].size() && v[i].size() != 1) {
			rt = i;
			break;
		}
	if (rt == -1) {
		F(i, 1, n) if (v[i].size()) cout << i << " "; cout << '\n';
		F(i, 1, n) if (v[i].size()) cout << i << " "; cout << '\n'; cout << '\n';
		return;
	}
	dfs(rt, 0);
	// cout << "! " << rt << " " << tot << endl;
	// F(i, 1, tot) cout << t[i] << " "; cout << endl;
	// F(i, 1, n)
	vector <pair <int, int>> ans;
	// puts("beg:");
	// F(i, 1, n) {
	// 	for (int j: v[i])
	// 		cout << i << " " << j << endl;
	// }
	// 	cout << "! " << rt << " " << v[rt].size() << " " << n << " " << tot << endl;
	if (tot % 2 == 0) {
		F(i, 1, n) {
			if (i == rt) continue;
			if (v[i].empty()) continue;
			if ((dfn[i] + rdfn[i] + 1) % 2) continue;
			int id = ((dfn[i] + rdfn[i]) / 2 - 1) % (tot / 2) + 1;
			// cout << "! " << i << " " << id << endl;
			// cout << "! " << (dfn[i] + rdfn[i]) / 2 << endl;
			// cout << "! " << i << " " << dfn[i] << " " << rdfn[i] << " " << id << endl;
			if (!s[id]) s[id] = i;
			else s[id] = -1;
		}
		F(i, 1, tot / 2) {
			if (s[i] == 0) {
				// cout << "@ " << i << endl;
				// cout << "! " << tot << endl;
				F(j, 1, tot / 2 + 1) {
					if (t[(i - j + tot) % tot + 1] == t[(i + j - 1) % tot + 1]) ans.emplace_back(t[(i - j + tot) % tot + 1], rt);
					else ans.emplace_back(t[(i - j + tot) % tot + 1], t[(i + j - 1) % tot + 1]);
				}
				break;
			}
			if (s[i] != -1) {
				// cout << "~ " << i << endl;
				// cout << "! " << i << " " << s[i] << endl;
				int ff;
				F(j, 1, tot / 2) {
					int A = t[(i - j + tot) % tot + 1], B = t[(i + j - 1) % tot + 1];
					if (dfn[s[i]] <= dfn[A] && rdfn[A] <= rdfn[s[i]]) {
						if (j == 1) ff = 1;
						else if (ff == 2) {
							ans.emplace_back(A, rt);
							ff = 3;
						}
					} else {
						if (j == 1) ff = 2;
						else if (ff == 1) {
							ans.emplace_back(s[i], rt);
							ff = 3;
						}
					}
					ans.emplace_back(A, B);
					// if (t[(i - j - a + tot) % tot + 1] == t[(i + j + b - 1) % tot + 1]) ans.emplace_back(t[(i - j - a + tot) % tot + 1], rt);
					// else ans.emplace_back(t[(i - j - a + tot) % tot + 1], t[(i + j + b - 1) % tot + 1]);
				}
				// puts("!");
				// cout << "! " << tot << endl;
				// int len = (rdfn[s[i]] - dfn[s[i]] + 1) / 2;
				// F(j, 1, len) ans.emplace_back(t[(i - j + tot) % tot + 1], t[(i + j - 1) % tot + 1]);
				// // cout << tot << " " << dfn[s[i]] << "  " << rdfn[s[i]] << " " << len << endl;
				// // ans.emplace_back(s[i], ff[s[i]]);
				// // if (m & 1)
				// ans.emplace_back(t[(i - len - 1 + tot) % tot + 1], s[i]);
				// F(j, len + 1, tot / 2) ans.emplace_back(t[(i - j - 1 + tot) % tot + 1], t[(i + j - 1) % tot + 1]);
				break;
			}
		}
	} else {
		F(i, 1, n) {
			if (v[i].empty()) continue;
			if (i == rt) continue;
			if ((dfn[i] + rdfn[i] + 1) % 2) {
				if (tot % 2) {
					int id = ((dfn[i] + rdfn[i]) / 2 + ((tot + 1) / 2) - 2) % tot + 1;
					// cout << "!! " << i << " " << dfn[i] << " " << id << endl;
					if (!s[id]) s[id] = i;
					else s[id] = -1;
				}
				continue;
			}
			int id = ((dfn[i] + rdfn[i]) / 2 - 1) % tot + 1;
			// cout << "! " << i << " " << id << endl;
			// cout << "! " << (dfn[i] + rdfn[i]) / 2 << endl;
			// cout << "! " << i << " " << dfn[i] << " " << rdfn[i] << " " << id << endl;
			if (!s[id]) s[id] = i;
			else s[id] = -1;
		}
		F(i, 1, tot) {
			// cout << "! " << i << " " << s[i] << endl;
			if (s[i] == 0) {
				// cout << "! " << tot << endl;
				F(j, 1, tot / 2 + 1) {
					if (t[(i - j + tot) % tot + 1] == t[(i + j - 1) % tot + 1]) ans.emplace_back(t[(i - j + tot) % tot + 1], rt);
					else ans.emplace_back(t[(i - j + tot) % tot + 1], t[(i + j - 1) % tot + 1]);
				}
				break;
			}
			if (s[i] != -1) {
				int a = 0;
				bool flag = true;
				F(j, 1, tot / 2) {
					int A = t[(i - j - a + tot) % tot + 1], B = t[(i + j - 1) % tot + 1];
					if (dfn[s[i]] <= dfn[A] && rdfn[A] <= rdfn[s[i]] && flag) {
						ans.emplace_back(A, rt);
						a++;
						A = t[(i - j - a + tot) % tot + 1];
						flag = false;
					}
					ans.emplace_back(A, B);
					// if (t[(i - j - a + tot) % tot + 1] == t[(i + j + b - 1) % tot + 1]) ans.emplace_back(t[(i - j - a + tot) % tot + 1], rt);
					// else ans.emplace_back(t[(i - j - a + tot) % tot + 1], t[(i + j + b - 1) % tot + 1]);
				}
				if (flag) {
					ans.emplace_back(s[i], rt);
				}
				// puts("!");
				// cout << "! " << tot << endl;
				// int len = (rdfn[s[i]] - dfn[s[i]] + 1) / 2;
				// F(j, 1, len) ans.emplace_back(t[(i - j + tot) % tot + 1], t[(i + j - 1) % tot + 1]);
				// // cout << tot << " " << dfn[s[i]] << "  " << rdfn[s[i]] << " " << len << endl;
				// // ans.emplace_back(s[i], ff[s[i]]);
				// // if (m & 1)
				// ans.emplace_back(t[(i - len - 1 + tot) % tot + 1], s[i]);
				// F(j, len + 1, tot / 2) ans.emplace_back(t[(i - j - 1 + tot) % tot + 1], t[(i + j - 1) % tot + 1]);
				break;
			}
		}
	}
	// cout << ans.size() << '\n';
	for (auto i: ans) cout << i.first << " " << i.second << '\n'; cout << '\n';
	assert(ans.size() == tot / 2 + 1);
}
signed main() {
	int _ = 1;
	cin >> _;
	F(i, 1, _) {
		// if (i == 331) {
		// 	int n; cin >> n;
		// 	cout << n << endl;
		// 	F(i, 1, n - 1) {
		// 		int x, y; cin >> x >> y;
		// 		cout << x << " " << y << endl;
		// 	}
		// 	return 0;
		// }
		zhk();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 20252kb

input:

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

output:

2 3
5 4
4 5

1 4 
1 4 

3 4
5 2

1 3
6 2
6 5


result:

ok All OK (4 test cases)

Test #2:

score: 0
Accepted
time: 44ms
memory: 21148kb

input:

100
2000
494 1815
316 280
704 103
1627 787
475 1616
401 744
1003 1901
46 66
428 1703
1865 450
1645 852
146 1488
469 1825
104 332
1638 1941
127 468
1558 350
373 1492
1287 1809
76 1479
1653 1243
1292 1465
922 1497
1891 459
1347 176
1996 1377
1182 1570
1461 742
1972 984
355 1412
650 338
1708 121
1869 1...

output:

1267 165
533 473
1613 1742
572 1976
819 406
158 683
1594 1591
698 1636
403 90
64 734
1855 902
147 1632
1683 75
1679 489
496 661
402 672
1128 1096
948 1760
1559 1284
1167 1773
716 1515
679 1648
540 1143
385 1764
735 901
9 1270
1834 1414
1579 1587
1409 916
99 925
1290 361
319 1361
1785 702
824 1225
17...

result:

ok All OK (100 test cases)

Test #3:

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

input:

100
2000
1312 1335
1335 1706
1913 1335
1335 896
1335 990
892 1335
1592 1335
1335 213
808 1228
1228 999
1335 332
1430 1335
1335 145
1335 901
1335 1269
1335 564
1335 843
1335 138
493 1335
1707 1335
1335 1368
754 1335
293 1335
1095 1335
355 1335
341 1335
37 1335
1335 1881
1455 1335
605 1335
1335 1322
1...

output:

128 130
1967 135
1963 143
1948 146
1937 147
1928 186
1926 236
1921 249
1916 290
1901 292
1888 302
1862 310
1824 335
1811 380
1809 399
1797 440
1781 442
1779 443
1758 458
1719 485
1697 490
1649 495
1618 503
1548 506
1523 518
1517 521
1513 579
1493 587
1466 590
1459 608
1387 631
1381 655
1371 661
2000...

result:

ok All OK (100 test cases)

Test #4:

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

input:

100
2000
478 1228
1201 702
874 1106
1043 1608
1010 1698
485 1592
1760 365
369 190
1268 104
250 1182
1530 1793
825 1236
1245 260
1818 551
626 652
979 1565
161 624
1302 1163
1109 1065
353 1342
1181 696
56 1061
905 396
411 1769
671 1715
1487 1906
761 1975
292 346
1889 175
527 1717
965 1780
1296 97
992 ...

output:

344 713 
344 713 

401 1059 
401 1059 

289 1569 
289 1569 

1072 1845 
1072 1845 

498 584 
498 584 

625 832 
625 832 

400 1656 
400 1656 

252 631 
252 631 

297 1451 
297 1451 

540 1379 
540 1379 

920 1475 
920 1475 

1598 1613 
1598 1613 

853 1645 
853 1645 

137 908 
137 908 

140 1204 
14...

result:

ok All OK (100 test cases)

Test #5:

score: 0
Accepted
time: 41ms
memory: 20712kb

input:

100
2000
1631 317
85 1099
180 616
35 1047
1478 164
1433 959
410 1733
371 1716
1885 1962
217 433
981 872
564 942
1370 655
142 718
1513 1897
1694 683
373 686
1965 833
384 1195
1430 1316
770 787
1456 292
831 166
834 1221
288 716
252 311
1974 1497
391 1603
675 369
542 141
1542 225
741 558
1762 1612
701 ...

output:

366 54
1887 1321
1419 521
1745 678
1969 835
1773 855
1730 106
1725 542
1648 751
1891 953
1880 34
1683 931
1434 1040
1157 1235
963 1240
916 1386
702 1756
513 70
476 660
1940 68
1792 637
1487 826
1437 850
1388 1285
1189 65
1932 1091
1689 1199
1657 1270
1976 1345
1841 1505
1662 19
1635 109
1068 646
991...

result:

ok All OK (100 test cases)

Test #6:

score: 0
Accepted
time: 44ms
memory: 19808kb

input:

100
2000
409 1935
85 1581
372 298
566 1538
462 1618
953 1566
1800 1220
1394 1061
553 318
1961 455
1318 168
935 339
1221 352
758 1219
1285 1093
889 948
1808 1849
446 801
1123 623
562 289
1923 5
1061 1276
618 523
865 1287
1143 1708
285 542
1545 1439
1350 72
2 999
956 1197
36 931
35 840
733 352
1481 39...

output:

353 1506
410 28
857 1032
431 1595
244 108
1748 1964
1001 1467
258 1602
1746 624
69 1899
190 1258
24 1711
1944 1288
3 1793
1242 860
1074 869
1383 677
63 1373
1511 1253
174 1812
773 471
420 593
217 752
135 1639
1415 342
1306 1702
1384 1201
104 1765
1633 1130
1440 1981
663 264
16 1706
911 641
5 1430
74...

result:

ok All OK (100 test cases)

Test #7:

score: 0
Accepted
time: 47ms
memory: 21080kb

input:

100
2000
360 1067
1071 386
1972 39
630 1817
68 777
91 353
683 1737
657 724
646 448
665 630
337 267
1274 769
977 1075
1177 93
122 1181
302 358
807 1078
1593 428
1301 563
485 1656
64 395
156 628
957 998
516 671
1809 556
765 1143
568 62
585 80
278 1533
38 373
593 1051
614 1262
929 1341
840 52
68 871
11...

output:

1540 1141
1485 1175
1949 1583
1915 1370
1750 1787
1459 1511
1333 1504
1946 1557
1961 1419
1874 1536
1493 1784
1813 1828
1688 1895
1383 1747
1601 1434
1727 1969
1218 1884
1620 1972
1798 1200
1480 1585
1737 1394
1694 1573
1611 1898
1261 1126
1446 1673
1668 1932
1260 1398
1202 1322
1359 1377
1214 1477
...

result:

ok All OK (100 test cases)

Test #8:

score: 0
Accepted
time: 115ms
memory: 46744kb

input:

1
200000
180867 117149
64957 96383
113663 34055
126334 46258
198365 156064
185941 135514
50922 102839
194187 170033
14353 188814
90500 114303
110852 84786
31360 45707
95366 181909
148219 102709
159594 15576
168829 128189
45621 36147
188648 157263
128090 120720
127728 147491
14102 46730
33752 29598
6...

output:

60759 33375
33349 173388
81814 45129
17266 90958
165761 18641
128919 67733
197661 148200
21367 160764
64550 108665
34769 124984
182591 68656
143722 167856
198893 48437
191348 165324
192568 7981
155798 181825
123683 1
149324 78966
28577 109414
166734 90606
106840 95525
197797 5638
141378 80467
177533...

result:

ok All OK (1 test case)

Test #9:

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

input:

1
200000
57440 116519
190896 104071
53012 156570
169755 24088
100818 109488
68779 96300
13283 199209
78123 93290
132729 23440
24264 45870
149108 173718
111047 115843
65821 56899
148506 51951
89726 142789
25286 193684
68947 178839
187345 179659
4349 165429
4425 40651
170136 128767
79833 30317
146012 ...

output:

46941 145849
42747 15195
154882 115010
97533 189970
82187 4703
181197 130780
80561 189389
44678 80159
189955 101363
151360 151289
60262 89574
130620 127877
60922 182663
48443 46720
189664 143584
138707 188017
31699 59615
189921 64350
186308 143374
72220 19100
188703 46399
123516 103049
81857 57162
1...

result:

ok All OK (1 test case)

Test #10:

score: 0
Accepted
time: 137ms
memory: 48404kb

input:

1
200000
135363 12419
12419 53087
12419 102176
12419 88147
12419 195924
12419 70946
12419 28021
12419 158923
143022 12419
12419 94981
111088 12419
12419 15202
12419 46491
128055 12419
12419 36839
167823 12419
12419 139603
12419 78361
85762 12419
117686 12419
88163 12419
153517 12419
72620 12419
5023...

output:

1 2
200000 3
199999 4
199998 5
199997 6
199996 7
199995 8
199994 9
199993 10
199992 11
199991 12
199990 13
199989 14
199988 15
199987 16
199986 17
199985 18
199984 19
199983 20
199982 21
199981 22
199980 23
199979 24
199978 25
199977 26
199976 27
199975 28
199974 29
199973 30
199972 31
199971 32
199...

result:

ok All OK (1 test case)

Test #11:

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

input:

1
200000
135705 108920
162642 126519
85128 45728
194271 180875
30763 93992
52969 151747
177074 20263
186614 109737
36694 190088
187500 16286
142641 75314
64550 33705
164299 102609
157504 28107
33788 158382
126297 44905
99420 168255
156403 81775
79011 196380
131864 94044
69591 100898
128825 102920
90...

output:

114579 132040 
114579 132040 


result:

ok All OK (1 test case)

Test #12:

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

input:

1
200000
165592 104127
37950 12293
64975 97946
93785 166716
164318 69986
196751 90865
23447 160715
54234 71862
85060 175999
184004 138041
150985 163147
85042 49367
159900 58574
85526 126934
144113 74917
11820 71982
98279 154765
15130 123668
24221 153534
45841 90041
76611 84919
102872 179527
184300 2...

output:

37245 12911
196446 31623
81415 19557
62259 72549
162172 58368
165631 99912
132996 112134
157978 128867
65132 100535
190294 121630
144213 27278
118739 145693
193967 171764
132274 51446
192056 45925
55324 35225
43831 84359
197350 92228
140166 152652
195898 173470
179985 10047
133663 24575
181808 29200...

result:

ok All OK (1 test case)

Test #13:

score: 0
Accepted
time: 128ms
memory: 44988kb

input:

1
200000
11163 181049
198878 80756
126047 10444
12318 170212
53148 108157
36484 184447
112205 28414
134930 72219
20670 20296
192695 128565
76596 10779
157783 84654
92158 63822
184965 173701
167017 53897
149981 198928
90046 175838
111705 34219
68811 89794
177259 199009
17328 121104
29446 68600
72687 ...

output:

65574 35807
100638 128276
172669 41807
62308 164282
17780 66344
3794 174606
114536 92959
60520 163100
184748 159888
103703 175114
71824 71797
13829 160942
120483 68766
81992 186174
97141 50153
72103 171138
62139 185613
39848 185676
148298 21630
25373 74179
107535 68412
85566 115194
173688 152660
620...

result:

ok All OK (1 test case)

Test #14:

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

input:

1
200000
4575 157468
164012 29131
19086 4026
40781 82891
37731 171364
63302 48036
74202 63605
197957 9856
13617 144515
52209 38724
21317 198083
80992 109217
166602 47381
33797 138331
25902 180272
167967 4317
61778 14894
56463 176107
190512 68141
73749 194304
28584 199885
34348 147657
17957 34484
492...

output:

136643 120679
103614 187107
147287 121600
145206 153275
166633 123793
155007 174615
163485 139941
134671 98146
108318 139574
194013 148203
134336 145484
130391 151678
107882 167068
199333 183151
115486 183493
96441 191323
157898 137155
123312 105351
112046 135701
105916 163238
172188 188506
184824 1...

result:

ok All OK (1 test case)

Test #15:

score: 0
Accepted
time: 68ms
memory: 24444kb

input:

10
20000
16695 1396
13278 3074
12587 14482
7700 15666
17027 19304
8306 4095
18254 12845
3902 15666
14183 1654
4204 14818
17061 8366
4939 9287
10390 13577
18352 7584
2963 12724
16669 3812
11375 11829
1776 12158
13184 13187
4759 587
19649 6559
14340 18587
10756 18874
8109 5657
1744 9320
5211 2432
8530...

output:

1002 2709
18287 5453
17989 5817
17555 11917
17456 13347
16812 13362
15729 15279
14819 17319
9247 18502
6853 19989
19610 138
18382 3242
13818 4879
12977 9370
8059 10576
6961 14209
1687 14704
1505 15573
1242 15877
162 19992
19202 1049
18626 1439
16108 4920
14684 4944
12926 5158
9916 5775
7070 12154
60...

result:

ok All OK (10 test cases)

Test #16:

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

input:

10
20000
2348 3282
5666 6279
5192 9950
18034 567
7661 12644
174 3177
4119 2354
9049 17783
16454 17069
18214 8601
17570 12771
10226 14634
14460 9186
4607 15080
12090 9391
5717 14991
12948 9659
5416 18709
19886 14470
12463 15501
17018 11949
11693 15997
8454 18550
403 2082
14833 18785
11044 11985
16832...

output:

13417 16821 
13417 16821 

3531 12180 
3531 12180 

5855 16588 
5855 16588 

11685 14039 
11685 14039 

9995 17242 
9995 17242 

2902 14871 
2902 14871 

654 8286 
654 8286 

5659 14901 
5659 14901 

6997 19044 
6997 19044 

5298 14536 
5298 14536 


result:

ok All OK (10 test cases)

Test #17:

score: 0
Accepted
time: 71ms
memory: 23956kb

input:

10
20000
10174 13411
3604 8329
19065 11752
9275 11429
5176 4143
7231 7102
10510 4779
7622 17899
13285 10649
537 13311
12745 6710
7318 15748
3795 6401
4566 18704
2280 9793
10628 15036
2979 4111
5315 2728
15154 5630
10512 9624
4389 1280
15002 1310
17714 11820
14385 16888
8595 11794
15253 6282
15438 78...

output:

2364 18315
8240 9794
8526 9835
16481 501
14979 5384
18849 1338
18497 7317
18851 15375
19017 4498
12025 3353
14712 8729
14719 345
17046 4783
3039 453
12466 5776
12104 6243
18104 2057
17541 10783
14612 11213
11807 15222
10773 8585
16807 14197
14128 14627
16241 5643
12224 8298
11611 10620
3538 1784
178...

result:

ok All OK (10 test cases)

Test #18:

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

input:

10
20000
6546 12178
8132 12698
9866 18394
4178 19311
18441 13775
13427 19385
9035 5234
18814 5897
13260 16823
240 19280
6194 12827
4971 193
12542 18512
18421 10994
1982 7222
17769 11520
19515 3324
7202 1207
11012 5144
9602 8684
11427 18573
4797 3230
10966 16392
331 4055
1990 9346
13 16133
12222 1776...

output:

8262 11102
3242 3
14127 962
10750 14962
11538 1049
2069 1176
14058 4232
10518 5206
4953 4180
1756 4548
16915 10470
11511 11741
10182 15330
6144 15344
13939 1514
4682 8291
18814 11872
8562 19622
6541 7131
1672 17285
17506 746
1504 8854
15284 7103
1122 7190
12221 8555
6804 9447
19382 283
13168 346
435...

result:

ok All OK (10 test cases)

Test #19:

score: 0
Accepted
time: 71ms
memory: 23064kb

input:

10
20000
18936 14226
19263 5838
8618 484
11997 12065
7555 4853
11170 19861
10053 8023
4674 1225
5681 11205
15958 2512
19545 13874
13344 14575
12557 12982
62 18520
4294 6383
14307 12269
9064 3353
12435 8926
5232 17514
2223 12758
16561 9385
15839 3786
5596 10714
2554 2704
7760 824
4795 4020
2501 9033
...

output:

15970 15669
15146 16167
18071 17955
17637 18189
16208 19537
18791 15982
18821 16876
19255 16031
15087 17079
17404 16053
18426 17326
15252 15294
15556 19657
18816 18767
16614 19750
19376 15921
16970 16550
18772 17902
18483 19065
15362 19439
18418 17336
17031 18029
15338 18348
17172 19025
16510 19140
...

result:

ok All OK (10 test cases)

Test #20:

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

input:

10
11312
7739 10213
4181 1027
4170 7024
9225 10206
3822 145
3713 8243
8815 1327
9962 736
318 1662
8562 48
9326 1002
5043 6009
928 8908
3571 837
10470 5661
3748 5909
1152 187
9538 2676
10704 8317
10457 4962
6777 9326
4163 4816
9384 6962
10183 531
4923 10222
9244 1092
10966 4894
8100 2154
10098 10331
...

output:

9144 6660
5509 10142
11287 5928
7618 6214
6523 1141
5829 6195
4023 566
2040 1380
8356 3014
3400 7806
9435 559
6383 2293
9765 1212
8964 7218
3076 851
2504 6096
11296 9251
6495 11198
2928 2461
1351 9137
11174 546
1418 9642
7056 4867
4056 9823
11246 747
10908 11227
7407 1003
6159 6135
7215 1542
5147 71...

result:

ok All OK (10 test cases)

Test #21:

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

input:

10
13449
12764 12936
5002 12959
8845 11434
4091 11415
4894 5002
5002 10608
8931 11149
5002 12709
9384 5473
690 8789
6033 4091
9384 6638
3921 853
9961 2907
3844 8931
7903 5040
4091 12458
8931 5188
5002 434
11434 3951
9380 11136
2487 8789
1878 8789
8931 12432
11095 11860
9380 9963
5457 9384
1460 3160
...

output:

11 17
13449 25
13416 51
13388 54
13380 57
13362 82
13361 89
13353 91
13332 108
13326 144
13313 155
13310 167
13285 177
13280 184
13253 237
13252 251
13223 318
13184 327
13170 335
13163 341
13158 360
13152 367
13148 406
13130 408
13107 432
13090 449
13083 456
13082 484
13073 512
13063 514
13054 524
1...

result:

ok All OK (10 test cases)

Test #22:

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

input:

10
14493
1833 13275
4628 13795
12867 5331
6564 9403
2075 824
4339 8792
7565 7906
3377 4104
4897 11749
4166 279
8310 8908
7842 11805
12951 8243
1363 10049
10426 6105
9824 3042
13787 4927
10620 13711
1528 8158
3726 7386
10532 13174
7863 5049
2000 10370
8750 10724
13438 11506
9107 1969
8538 9710
12047 ...

output:

2864 8179 
2864 8179 

3471 12882 
3471 12882 

5072 14829 
5072 14829 

8734 17332 
8734 17332 

156 8474 
156 8474 

13894 18999 
13894 18999 

1990 6687 
1990 6687 

292 7642 
292 7642 

56 7508 
56 7508 

4697 8655 
4697 8655 


result:

ok All OK (10 test cases)

Test #23:

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

input:

10
14128
4498 9745
468 10727
4183 2924
10397 10422
1609 3728
10527 7958
5257 11781
7375 7137
13836 9986
7752 10497
13775 5728
5447 5105
6533 1593
9563 6546
7393 5921
9997 4083
11092 6797
13298 4550
13289 13066
4846 12542
4781 9790
11309 12700
1777 205
3315 1167
8709 13799
10721 12965
10146 7479
4004...

output:

1292 3651
9148 10391
13360 2996
7728 605
9124 2454
11400 3828
7191 4576
11457 7092
12048 4433
9536 1929
4269 4011
3297 662
8691 318
12410 13446
8032 2666
13145 3404
12596 7420
7569 4514
5412 488
7581 410
11282 3397
3632 187
11528 1354
12461 619
5124 5782
10002 8417
11903 814
11121 570
6247 1319
4493...

result:

ok All OK (10 test cases)

Test #24:

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

input:

10
14665
1098 13101
7459 8501
3771 4992
6274 13209
9606 1624
2135 2263
5347 1754
14289 503
10856 301
8122 3811
3486 4024
9088 13875
1278 5408
5225 11456
5308 1475
2986 11799
9520 13971
12003 4141
3747 7910
1139 3798
11481 864
9160 7180
388 12570
7448 9300
4447 4504
6907 8665
11666 12682
11943 12211
...

output:

3615 9886
4287 2
8582 1732
6840 2939
1802 11546
1078 14122
11768 8519
1955 12922
10865 3314
9630 13656
11904 280
1642 646
14295 5340
1062 6941
10651 8017
3659 13441
9212 7410
2177 12804
14585 2406
3038 10008
13729 6712
9558 11001
5929 8781
1910 13015
6343 5468
1787 12119
11080 7463
5554 8007
13536 6...

result:

ok All OK (10 test cases)

Test #25:

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

input:

10
14823
13851 10092
4469 5824
10539 681
5633 4009
11591 2052
9154 2692
2257 4439
7270 391
8135 8998
10371 6008
7953 1123
1917 13346
4253 8134
3141 13970
7216 8485
7217 8044
11904 9026
6879 6256
1758 5875
9127 13292
9266 3451
9418 956
5396 4746
12136 13171
438 5174
4770 8211
4249 10630
11931 7668
30...

output:

13274 13360
14566 13362
14209 12749
14693 13293
13174 13127
14526 13284
12905 14416
13417 13841
13750 14469
13095 12888
13200 13447
13000 14498
13323 14590
13854 14631
13791 14587
14420 12787
13803 12708
13437 12738
14300 13618
13706 13836
13245 14178
13288 14646
13326 13055
14382 13855
13608 13687
...

result:

ok All OK (10 test cases)

Test #26:

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

input:

10
17485
5940 14053
2276 5018
8057 1985
12859 3478
12866 1646
5885 12915
15736 3531
17200 2938
6878 13777
10761 6120
4713 14167
2618 16233
5813 6420
13393 4642
9632 2985
1342 16025
16026 6844
6319 1649
5802 1215
2849 11681
15859 413
7453 3222
9492 5313
2309 13965
1361 8932
8017 5935
2256 7595
3056 8...

output:

16381 16535
10943 25
16152 16189
16786 16959
17298 16866
16994 17248
17460 16865
17227 16819
16844 16960
16868 16171
17123 16880
16978 17409
17158 16335
17102 16973
17066 17414
16536 16722
16367 17476
17247 16265
16217 16435
16842 16569
16662 16893
16430 16482
16712 16208
17290 16810
17423 17420
166...

result:

ok All OK (10 test cases)

Test #27:

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

input:

10
20000
7885 7071
16024 2454
788 1532
9107 5396
863 18365
13559 14595
5682 17596
10277 5565
5429 9775
9651 1543
10997 1585
15843 98
11709 18346
18893 357
19664 6276
4638 4202
11311 4463
13733 1689
19245 7795
4812 13596
11676 16057
16039 7395
9202 12081
19418 3855
10091 15515
9706 18698
16415 17647
...

output:

18902 19215
19895 19425
19190 19478
19188 19789
18778 19246
19901 19749
19780 19023
19943 19296
19596 19697
19480 19288
19251 19700
19640 18748
18982 19041
18865 18951
18810 19232
19965 19602
19960 19307
19544 19445
18859 19688
18871 19891
19095 19046
19546 19912
19751 19381
19631 19047
19437 18942
...

result:

ok All OK (10 test cases)

Test #28:

score: 0
Accepted
time: 53ms
memory: 22956kb

input:

10
20000
13043 670
237 4915
10906 409
19253 711
16317 876
742 15465
12586 690
796 16349
6763 627
868 3775
13797 715
13416 216
6989 798
136 8115
17811 451
18310 626
8943 534
376 1364
629 17957
719 5463
4847 46
3220 704
735 19173
17824 290
803 12001
9695 326
3717 696
156 16563
394 6627
3829 779
267 14...

output:

1245 2518
19424 2948
16520 4063
15360 4251
14832 5849
14695 5956
12650 6349
11984 7855
10642 8301
10058 8408
9984 8557
9716 9775
9634 10109
9119 10767
7826 11518
7726 11539
7169 12767
6786 12811
6713 13205
5726 14494
5288 16104
4090 19414
3511 1560
19676 2416
19581 2821
19208 3993
17671 5423
17586 6...

result:

ok All OK (10 test cases)

Test #29:

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

input:

100
2000
1527 25
35 1691
1381 12
1214 51
67 1058
67 1122
195 75
883 16
316 30
13 645
75 577
34 604
1988 32
86 9
47 579
1453 38
97 431
727 83
1939 26
1533 97
68 1142
80 1675
39 1352
45 1302
96 154
49 1402
26 1388
1091 93
70 1804
97 1577
77 28
1667 20
5 1602
189 21
545 42
10 1495
13 337
30 6
1799 7
52...

output:

146 181
1999 483
1886 626
1426 744
1408 1112
1340 1136
1305 1146
1297 1282
1164 1361
1132 1459
1022 1517
951 1526
808 1562
806 1743
438 1750
423 1827
406 1877
361 1972
108 188
1974 263
1725 329
1698 411
1650 461
1565 466
1008 720
864 741
561 791
395 883
336 927
162 1415
150 1446
100 1487
1838 1612
1...

result:

ok All OK (100 test cases)

Test #30:

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

input:

100
2000
420 1219
945 1001
574 759
1646 1989
741 1939
54 210
1344 1645
832 1111
1685 1932
1581 612
1481 640
1634 928
971 924
136 1844
813 1516
860 331
103 1243
381 1348
839 849
423 1443
1766 1675
1462 513
961 1563
793 1687
378 279
1305 1510
818 966
668 1327
1133 1012
1356 1630
819 1261
70 521
1314 6...

output:

1991 1981
1982 1996
1995 1990
1992 1998
1988 1987
1997 1999
1979 1983
1985 1986
2000 1994
1978 1984
1989 1993
1980 70

1982 1951
1981 1936
1977 1943
1949 1966
1923 1985
1927 1968
1987 1948
1933 1989
1922 1916
1930 1939
1940 1959
1954 1961
1984 1963
1983 1992
1932 1938
1956 1969
1946 1994
1918 1955
1...

result:

ok All OK (100 test cases)

Test #31:

score: 0
Accepted
time: 146ms
memory: 48272kb

input:

1
200000
75527 3156
2623 154626
2558 177113
146357 1358
2656 186051
187792 523
4363 90605
100704 4773
87808 3697
502 173074
86283 3548
197007 2319
2809 174049
52610 666
1359 164293
25456 2472
4304 188852
4561 165894
180375 3811
5190 90244
199525 659
23244 4464
142850 282
690 124332
164450 5136
15018...

output:

5842 16721
199634 18306
198859 20642
198003 27414
197148 29457
194885 30649
191077 54839
188309 56249
174821 63240
168305 65143
153727 70420
151988 78377
151955 86280
151282 95010
148902 110398
145839 113397
144387 114371
136979 122970
132640 130045
131617 133701
126674 142157
115735 142902
102042 1...

result:

ok All OK (1 test case)

Test #32:

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

input:

1
200000
83931 96937
32952 195907
78310 37108
176347 23132
188809 37384
140706 23700
17636 158568
5634 155262
58194 33410
47523 166455
128642 18909
178740 165831
85365 160502
187890 58358
25450 91847
140606 122655
63185 138517
189170 33052
136599 125275
91736 43965
108429 73952
40581 92844
147701 19...

output:

199996 199989
199988 199991
199993 199992
199998 199997
199995 199994
199990 200000
199999 9232


result:

ok All OK (1 test case)

Test #33:

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

input:

1
200000
193597 17230
27229 185684
159770 185467
10684 16681
197494 65016
145960 136670
147327 154108
79903 91787
146348 95359
23027 12513
23620 155067
337 181961
81189 147340
97553 64534
60153 114240
87847 125869
29991 186766
75418 153252
30768 107217
128834 162883
28777 29024
94836 138175
140266 1...

output:

199708 199282
199130 199344
109091 292
199937 199376
199299 199829
199604 199685
199193 199618
199380 199695
199448 199119
199232 199488
199994 199595
199632 199407
199151 199612
199409 199360
199900 199634
199530 199921
199666 199796
199969 199152
199763 199118
199713 199967
199142 199644
199102 19...

result:

ok All OK (1 test case)