QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#328329#3307. Query on a Tree 17a_z_cWA 291ms32136kbC++203.3kb2024-02-15 19:14:492024-02-15 19:14:50

Judging History

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

  • [2024-02-15 19:14:50]
  • 评测
  • 测评结果:WA
  • 用时:291ms
  • 内存:32136kb
  • [2024-02-15 19:14:49]
  • 提交

answer

#include<bits/stdc++.h>
//#define N2MENT
#ifdef N2MENT
	#define LOG(...) fprintf(stderr,__VA_ARGS__), void(0)
#else
	#define LOG(...) void(0)
#endif
using namespace std;
using ll = long long;
const int maxn = 1e5 + 10;
class SegTree {
public:
	ll tr[maxn << 2], lazy[maxn << 2];
	void __update(int k) {
		tr[k] = tr[k << 1] + tr[k << 1 | 1];
	} 
	void __push(int k, int l, int r) {
		if(!lazy[k]) return;
		int mid = (l + r) >> 1;
		tr[k << 1] += lazy[k] * (mid - l + 1);
		tr[k << 1 | 1] += lazy[k] * (r - mid);
		lazy[k << 1] += lazy[k];
		lazy[k << 1 | 1] += lazy[k];  
		lazy[k] = 0;
	}
	void modify(int k, int l, int r, int L, int R, ll val) {
		if(L <= l && r <= R) {
			tr[k] += val * (r - l + 1);
			lazy[k] += val;
			return;
		}
		__push(k, l, r);
		int mid = (l + r) >> 1;
		if(L <= mid) modify(k << 1, l, mid, L, R, val);
		if(R > mid) modify(k << 1 | 1, mid + 1, r, L, R, val);
		__update(k);
	} 
	ll query(int k, int l, int r, int L, int R) {
		if(L <= l && r <= R) return tr[k];
		__push(k, l, r);
		int mid = (l + r) >> 1;
		ll res = 0;
		if(L <= mid) res += query(k << 1, l, mid, L, R);
		if(R > mid) res += query(k << 1 | 1, mid + 1, r, L, R);
		return res;
	}
	int find(int k, int l, int r, ll val) {
		if(tr[k] < val) return -1;
		if(l == r) return l;
		__push(k, l, r);
		int mid = (l + r) >> 1;
		int res = find(k << 1, l, mid, val);
		if(~res) return res;
		return find(k << 1 | 1, mid + 1, r, val - tr[k << 1]);
	}
}sgt;
vector<int> G[maxn];
int fa[maxn][20], siz[maxn], son[maxn], top[maxn], dep[maxn], id[maxn], rev[maxn], cnt;
int n;
void dfs1(int u, int f) {
	fa[u][0] = f;
	dep[u] = dep[f] + 1;
	siz[u] = 1;
	for(int i = 1; i < 20; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];
	for(int v : G[u]) {
		if(v == f) continue;
		dfs1(v, u);
		siz[u] += siz[v];
		if(!son[u] || siz[son[u]] < siz[v]) son[u] = v;
	} 
}
void dfs2(int u, int tp) {
	id[u] = ++cnt;
	rev[cnt] = u;
	top[u] = tp;
	if(son[u]) dfs2(son[u], tp);
	for(int v : G[u]) {
		if(v == fa[u][0] || v == son[u]) continue;
		dfs2(v, v);
	}
}
int Query() {
	ll sum = sgt.query(1, 1, n, 1, n);
	int m = (sum >> 1) + 1;
	int u = rev[sgt.find(1, 1, n, m)];
	while(sgt.query(1, 1, n, id[top[u]], id[top[u]] + siz[top[u]] - 1) < m) u = fa[top[u]][0];
	if(sgt.query(1, 1, n, id[u], id[u] + siz[u] - 1) >= m) return u;
	for(int i = 19; ~i; i--) if(fa[u][i] && sgt.query(1, 1, n, id[fa[u][i]], id[fa[u][i]] + siz[fa[u][i]] - 1) < m) u = fa[u][i];
	return fa[u][0];
}
void ModifySubtree(int u) {
	sgt.modify(1, 1, n, id[u], id[u] + siz[u] - 1, 1);
}
void ModifyChain(int u, int v) {
	while(top[u] != top[v]) {
		if(dep[top[u]] < dep[top[v]]) swap(u, v);
		sgt.modify(1, 1, n, id[top[u]], id[u], 1);
		u = fa[top[u]][0];
	}
	if(dep[u] > dep[v]) swap(u, v);
	sgt.modify(1, 1, n, id[u], id[v], 1);
}
int main() {
#ifndef N2MENT
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	for(int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}
	dfs1(1, 0);
	dfs2(1, 1);
	int q;
	cin >> q;
	while(q--) {
		int op, u, v;
		cin >> op;
		if(op == 1) {
			cin >> u;
			ModifySubtree(u);
		} else {
			cin >> u >> v;
			ModifyChain(u, v);
		}
//		for(int i = 1; i <= n; i++) LOG("%d ", sgt.query(1, 1, n, id[i], id[i]));
//		LOG("\n");
		cout << Query() << '\n';
	}
	
}

详细

Test #1:

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

input:

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

output:

2
7
7
1

result:

ok 4 lines

Test #2:

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

input:

15
1 2
1 3
2 4
3 7
6 2
3 8
4 9
2 5
5 11
7 13
10 4
11 15
12 5
14 7
11
2 6 11
1 6
2 10 9
1 9
2 2 6
1 4
2 7 6
1 2
2 8 13
1 10
2 8 15

output:

2
2
2
2
2
2
2
2
2
2
2

result:

ok 11 lines

Test #3:

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

input:

2
1 2
1
1 1

output:

1

result:

ok single line: '1'

Test #4:

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

input:

2
1 2
1
2 1 2

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 5ms
memory: 7884kb

input:

100
1 2
58 2
2 87
63 87
65 63
65 19
6 87
58 21
87 8
87 74
91 6
95 65
2 61
87 59
3 61
37 87
67 87
23 2
63 9
87 46
40 67
70 2
12 58
46 75
75 36
28 3
12 33
72 87
39 6
75 52
85 70
1 76
26 40
47 28
2 49
41 65
66 28
51 37
15 47
86 51
8 60
97 19
48 58
72 90
33 83
97 54
36 5
23 14
78 52
90 7
99 2
48 82
48 6...

output:

72
3
3
87
87
2
2
2
2
87
87
87
87
87
2
87
87
87
87
87
87
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87
87...

result:

ok 10000 lines

Test #6:

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

input:

100
27 1
27 35
96 1
54 35
25 54
81 35
69 25
27 18
69 83
27 99
70 83
81 61
1 77
73 54
35 68
61 89
20 89
99 95
37 20
63 95
95 38
7 83
63 78
86 35
89 13
71 77
70 14
95 34
13 62
24 95
77 98
99 33
25 100
36 63
35 8
65 54
66 83
40 8
15 81
78 59
15 4
62 28
97 14
15 58
69 3
89 44
47 100
52 73
12 95
53 38
39...

output:

46
35
46
83
83
83
83
35
35
35
25
25
25
35
25
25
25
25
25
54
54
35
35
35
54
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
35
...

result:

ok 10000 lines

Test #7:

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

input:

100
1 19
19 45
58 45
58 72
36 45
45 94
94 13
90 58
64 90
90 23
45 12
90 52
27 36
19 42
72 35
23 32
67 36
1 18
54 36
33 67
10 1
55 90
54 65
92 72
53 42
65 24
9 45
81 42
85 35
8 81
10 44
85 68
23 30
69 12
43 69
23 25
12 88
85 99
91 9
24 100
48 81
60 94
33 41
52 51
17 19
51 82
30 49
32 28
52 7
82 79
82...

output:

33
45
45
45
45
45
58
58
58
58
58
45
58
45
58
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
45
...

result:

ok 10000 lines

Test #8:

score: 0
Accepted
time: 5ms
memory: 5792kb

input:

100
67 1
34 67
34 72
26 72
63 26
26 14
63 24
63 49
42 14
45 34
14 71
71 87
71 7
14 22
64 72
90 7
14 58
87 99
33 87
24 70
65 64
42 30
33 74
99 62
3 71
60 90
84 90
40 70
47 45
84 69
89 7
57 3
99 59
66 65
58 76
37 14
6 37
72 54
38 24
15 99
51 84
93 76
59 8
89 53
75 51
97 99
20 8
28 53
95 15
11 53
95 13...

output:

21
37
14
14
14
14
71
14
14
14
14
14
14
14
14
14
14
14
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
14
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
71
...

result:

ok 10000 lines

Test #9:

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

input:

100
1 56
1 65
50 1
50 4
4 8
4 27
31 8
10 50
25 10
31 28
31 64
97 25
44 64
16 4
44 89
43 64
89 23
33 43
37 33
10 13
90 43
26 37
97 39
16 52
10 12
20 39
33 78
36 37
37 34
79 1
34 3
20 32
25 77
81 78
35 20
82 25
35 19
35 74
5 20
63 39
38 43
37 66
89 42
57 19
3 18
19 69
100 90
59 69
45 78
34 88
69 60
35...

output:

77
50
77
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
10
10
10
10
10
10
10
10
50
50
50
10
50
50
50
10
50
50
50
10
50
50
50
10
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
4
4
4
4
4
50
50
50
50
50
50
50
50
50
50
50
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4...

result:

ok 10000 lines

Test #10:

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

input:

100
1 13
4 1
57 4
13 30
4 73
30 78
30 25
28 30
64 57
4 52
25 83
66 64
99 64
21 28
25 98
28 14
28 7
99 39
13 71
74 99
7 31
14 72
72 45
74 68
79 83
79 93
83 20
11 30
4 95
7 18
86 83
88 68
72 6
32 30
97 95
90 7
89 97
99 29
26 90
90 5
66 67
90 91
49 30
90 51
87 39
28 24
5 22
72 38
50 24
80 74
88 9
81 95...

output:

50
30
28
30
28
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
...

result:

ok 10000 lines

Test #11:

score: 0
Accepted
time: 5ms
memory: 7868kb

input:

100
11 1
1 46
1 55
46 65
43 46
84 1
11 73
77 46
1 78
46 92
81 55
28 55
11 6
1 16
14 78
95 46
1 18
22 77
10 73
65 88
37 11
34 6
14 32
74 16
16 27
43 58
89 1
50 1
55 30
11 38
45 55
92 33
67 78
92 75
80 22
73 23
79 43
69 28
25 78
85 11
65 82
77 99
32 97
2 16
65 62
42 73
46 72
83 58
67 53
100 28
14 51
3...

output:

40
77
46
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
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 10000 lines

Test #12:

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

input:

100
1 17
78 17
1 24
17 34
24 70
67 24
78 36
17 13
94 1
1 32
36 80
17 50
15 1
78 92
53 78
32 79
28 1
34 30
21 50
67 49
62 67
25 15
61 80
94 73
36 72
71 13
67 85
46 15
13 54
70 4
28 3
33 24
32 18
79 19
5 32
26 73
99 94
75 33
39 25
63 71
61 84
29 73
100 17
5 88
2 34
3 6
68 92
4 11
5 82
39 23
49 69
87 5...

output:

31
1
31
32
32
32
32
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
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 10000 lines

Test #13:

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

input:

100
95 1
87 1
95 72
99 95
76 1
67 95
54 1
50 72
94 95
1 29
99 78
52 54
25 1
27 76
27 48
18 50
48 32
54 9
44 29
31 72
63 50
36 95
57 99
81 99
52 39
29 47
28 94
47 42
87 93
98 78
16 32
44 12
18 100
34 57
20 95
31 70
63 13
69 31
9 17
68 47
76 49
48 30
95 71
44 56
14 94
2 50
98 43
79 49
53 87
8 81
75 52...

output:

14
95
95
95
95
95
95
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
1
95
1
95
95
95
95
95
1
95
95
95
95
95
1
95
1
1
1
1
1
95
95
95
95
95
1
1
1
1
1
...

result:

ok 10000 lines

Test #14:

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

input:

100
43 1
4 43
90 4
90 9
56 9
56 53
57 53
57 74
47 74
47 27
25 27
25 62
44 62
44 12
81 44
81 87
88 12
21 87
42 87
42 18
31 42
18 67
41 31
21 71
71 30
60 41
17 60
26 41
96 17
96 100
100 94
86 94
50 94
39 94
35 86
82 39
100 55
3 100
92 30
20 86
3 93
22 20
14 20
99 82
93 79
50 33
15 22
58 15
79 36
15 32...

output:

20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
20
20
20
86
20
20
20
86
86
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
86
86
86
86
20
20
...

result:

ok 10000 lines

Test #15:

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

input:

100
1 5
98 5
82 98
2 82
98 47
47 77
40 77
40 38
38 99
38 32
59 32
59 50
94 50
94 88
45 94
51 45
15 88
55 45
73 45
8 55
83 8
57 83
81 83
55 11
90 8
62 11
11 12
36 90
62 30
48 30
36 20
36 25
27 25
17 25
24 30
42 25
25 52
84 42
42 95
65 42
42 33
33 16
74 95
63 65
63 22
22 13
65 70
13 64
85 70
22 43
79 ...

output:

77
77
35
55
55
55
42
42
42
42
65
65
65
65
85
85
85
85
31
85
85
85
85
65
65
65
85
65
65
65
65
65
65
65
65
65
65
65
85
85
85
85
85
85
85
85
93
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
65
65
65
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
85
...

result:

ok 10000 lines

Test #16:

score: 0
Accepted
time: 5ms
memory: 7728kb

input:

100
61 1
61 14
14 21
21 15
21 5
65 5
5 64
64 77
80 77
58 80
80 85
18 85
58 13
29 13
79 29
12 79
12 66
66 48
95 66
95 33
95 76
76 49
93 49
88 93
83 49
88 17
57 48
88 3
3 25
25 9
9 71
71 75
75 6
97 6
97 26
26 28
87 71
6 78
86 28
86 81
24 17
81 94
37 24
94 54
37 4
35 81
67 4
94 10
67 46
10 47
73 10
19 ...

output:

85
80
88
88
9
88
88
88
88
88
88
88
88
88
88
88
88
88
88
88
9
9
9
88
9
25
25
88
88
88
25
88
25
25
25
25
9
9
71
71
75
71
71
71
71
71
75
71
71
71
71
71
71
71
71
71
71
71
75
75
6
75
75
71
75
71
75
71
75
71
71
71
71
71
71
71
71
71
71
9
9
25
25
25
25
88
25
88
88
88
88
88
88
88
88
88
88
88
88
88
88
88
88
8...

result:

ok 10000 lines

Test #17:

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

input:

100
8 1
93 1
66 1
82 1
88 1
1 96
77 1
8 38
8 70
19 1
1 20
1 43
1 95
1 80
1 29
92 1
56 1
71 1
8 73
62 82
1 78
1 87
8 76
1 45
22 77
8 6
54 1
1 46
1 58
50 66
34 1
28 93
66 30
66 15
38 85
1 9
93 61
8 16
66 48
93 14
93 90
27 1
21 1
93 44
1 60
8 51
66 65
95 84
4 8
83 88
32 93
11 8
40 88
1 74
1 7
96 35
93 ...

output:

6
8
8
8
8
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
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 10000 lines

Test #18:

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

input:

100
1 66
76 1
41 1
1 6
1 38
67 66
31 1
91 1
1 96
42 1
1 5
41 16
1 30
59 66
28 76
1 58
66 43
41 68
1 48
78 1
1 60
72 76
61 1
15 1
94 1
66 27
1 4
38 29
38 20
23 66
10 76
36 6
75 41
37 1
6 13
19 76
76 35
1 18
1 86
1 49
44 1
1 64
6 85
1 39
80 5
1 71
1 7
66 34
56 41
76 92
65 91
8 76
41 33
99 6
1 51
93 58...

output:

87
1
87
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
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 10000 lines

Test #19:

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

input:

100
1 25
72 1
1 16
1 96
55 1
11 1
26 1
2 1
1 37
8 25
72 6
1 4
1 13
46 25
31 1
99 1
21 1
1 10
52 1
83 72
86 1
16 22
49 16
72 80
76 1
1 15
35 1
44 25
33 1
66 11
91 11
43 72
85 1
7 1
54 72
94 1
50 16
32 16
28 72
1 20
16 59
1 48
14 72
84 25
16 17
58 1
63 26
97 25
57 55
65 26
61 16
19 1
16 92
95 1
2 74
1...

output:

78
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
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 10000 lines

Test #20:

score: 0
Accepted
time: 209ms
memory: 23660kb

input:

100000
1 33107
1 49683
49683 23838
33107 33841
25927 23838
1 74779
99345 74779
36731 99345
23838 70246
38975 49683
36605 74779
49283 1
72218 49283
36605 89277
16724 49283
15597 89277
74779 70693
25927 10882
18787 49683
49283 89923
74779 18891
18891 72904
70246 64950
74779 39040
51544 39040
48338 722...

output:

89754
28789
33107
33107
49683
49683
49683
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
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 100000 lines

Test #21:

score: 0
Accepted
time: 158ms
memory: 24472kb

input:

100000
1 98526
98526 71881
71881 32316
71881 91701
97004 71881
1 50154
50154 25648
90382 32316
98526 51008
81074 71881
88290 91701
20835 81074
1 88584
81163 1
5066 98526
63220 71881
5066 43945
88290 89171
97004 78551
49986 91701
53367 88584
50154 89663
50154 90725
98456 89663
90382 74858
90725 53584...

output:

94781
47260
71881
66830
1649
81074
20703
66830
66830
66830
35108
20703
66830
66830
20703
20703
20703
20703
20703
20703
20703
20703
20703
66830
66830
20703
20703
1649
1649
1649
1649
1649
1649
81074
81074
81074
81074
81074
81074
81074
81074
81074
81074
81074
81074
81074
81074
81074
81074
81074
81074
8...

result:

ok 100000 lines

Test #22:

score: 0
Accepted
time: 109ms
memory: 23300kb

input:

100000
98458 1
18530 1
95442 1
98458 2967
97766 95442
18530 5382
5382 45839
97766 70789
97766 46371
51056 70789
2100 5382
97766 40344
193 98458
18530 45452
2967 91534
5382 71051
68600 5382
65092 2967
43663 70789
66738 1
20267 95442
2100 61712
39565 66738
95442 56590
29031 61712
8607 91534
91681 5105...

output:

98813
97766
97766
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
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 100000 lines

Test #23:

score: 0
Accepted
time: 126ms
memory: 23516kb

input:

100000
1 93030
48178 93030
1655 1
93030 95380
15742 95380
15742 38782
49563 93030
93030 94593
38782 10482
94593 62811
62811 38444
62630 93030
23379 1
66269 95380
15320 66269
69627 1
93030 637
10482 46696
62570 66269
43085 69627
40421 15320
40421 29280
38444 29544
13323 29280
15320 51097
13323 33995
...

output:

57889
1
1
1
93030
93030
93030
1
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
93030
9303...

result:

ok 100000 lines

Test #24:

score: 0
Accepted
time: 105ms
memory: 22928kb

input:

100000
1 46788
46788 74831
38318 46788
46788 28121
28121 85162
46788 24705
62068 1
46788 86508
24705 85078
80001 24705
91029 80001
62068 55738
62068 11972
62068 80422
11972 36665
36665 81942
28121 85074
85078 35507
85074 93487
46788 65180
2803 46788
67158 85074
11972 30193
6547 36665
67785 55738
543...

output:

10039
1
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
46788
4678...

result:

ok 100000 lines

Test #25:

score: 0
Accepted
time: 86ms
memory: 22960kb

input:

100000
1 86599
1715 1
86599 79823
65172 1715
93401 79823
18478 1
95324 18478
1534 79823
86599 40049
18478 84772
88749 40049
33592 84772
20450 93401
72786 33592
54506 79823
49207 20450
20450 52827
40049 32100
51159 1
51159 69551
52827 83745
1974 51159
7678 32100
2139 93401
53523 69551
26607 40049
847...

output:

90253
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
86599
1
1
1
1
1
86599
1
1
1
86599
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
86599
86599
86599
1
86599
1
86599
1
86599
86599
86599
1
86599
86599
86599
86599
86599
86599
86599
86599
86599
86599
86599
86599
8659...

result:

ok 100000 lines

Test #26:

score: 0
Accepted
time: 291ms
memory: 32136kb

input:

100000
66827 1
66827 3020
37001 3020
86421 37001
48188 86421
48188 66366
64459 66366
64459 70776
70776 88217
88217 53546
53546 60759
94219 60759
52771 94219
52771 1872
1872 33491
33491 15705
78366 15705
68591 78366
68591 70054
70054 94898
94898 37055
83477 37055
83477 61881
61881 39144
39144 70057
7...

output:

75000
33373
7590
64240
43814
89834
70488
29117
71794
43268
14768
42809
43375
25401
40632
33598
46593
645
20236
3674
36430
65000
92273
25595
56960
55003
45432
70243
77446
16509
4099
20265
66645
34989
58809
98353
9329
62421
97020
6494
64065
50143
23005
99419
84985
21578
77627
75730
39291
63567
59463
1...

result:

ok 100000 lines

Test #27:

score: -100
Wrong Answer
time: 217ms
memory: 31184kb

input:

100000
17714 1
9191 17714
99673 9191
65651 99673
65651 11385
11385 2682
28082 2682
34681 28082
34681 38648
65899 38648
9099 65899
5024 9099
83703 5024
9649 83703
9649 33178
98045 33178
98045 41340
41340 94118
27384 94118
27384 68738
45636 68738
14788 45636
14788 74533
76190 74533
27493 76190
27493 6...

output:

19816
16751
92098
59112
95318
51697
31218
7148
61778
28385
74434
85323
65962
51202
63974
35110
43035
58792
36169
46581
25438
24399
48959
74508
43446
74498
81711
65260
96892
35539
53879
80120
75837
84884
56306
10374
38768
48702
42349
16439
12177
66088
75848
34280
81648
43035
33126
38354
25635
33771
1...

result:

wrong answer 69541st lines differ - expected: '18638', found: '1'