QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722204#9570. Binary Treeucup-team4474#AC ✓234ms14812kbC++203.6kb2024-11-07 18:10:222024-11-07 18:10:23

Judging History

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

  • [2024-11-07 18:10:23]
  • 评测
  • 测评结果:AC
  • 用时:234ms
  • 内存:14812kb
  • [2024-11-07 18:10:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

bool Memory_begin;

bool Memory_end;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cerr << (&Memory_end - &Memory_begin) / 1048576.0 << "MB" << '\n';

    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<vector<int>> adj(n + 1);
        for (int i = 1, x, y; i <= n; i++)
        {
            cin >> x >> y;
            if (x)
                adj[i].push_back(x), adj[x].push_back(i);
            if (y)
                adj[i].push_back(y), adj[y].push_back(i);
        }
        vector<int> vis(n + 1);

        int sum = n;
        while (sum > 1)
        {
            vector<int> dep(n + 1), siz(n + 1);
            auto dfs0 = [&](auto &dfs0, int cur, int fa) -> void
            {
                siz[cur] = 1;
                for (int i : adj[cur])
                {
                    if (i == fa or vis[i])
                        continue;
                    dfs0(dfs0, i, cur);
                    siz[cur] += siz[i];
                }
            };
            auto dfs1 = [&](auto &dfs1, int cur, int fa, int sum) -> int
            {
                int mx = sum - siz[cur];
                for (int i : adj[cur])
                {
                    if (i == fa or vis[i])
                        continue;
                    int tmp = dfs1(dfs1, i, cur, sum);
                    if (tmp)
                        return tmp;
                    mx = max(mx, siz[i]);
                }
                if (mx * 2 <= sum)
                    return cur;
                return 0;
            };
            auto dfs2 = [&](auto &dfs2, int cur, int fa) -> void
            {
                dep[cur] = dep[fa] + 1;
                for (int i : adj[cur])
                {
                    if (vis[i] or i == fa)
                        continue;
                    dfs2(dfs2, i, cur);
                }
            };
            for (int i = 1; i <= n; i++)
            {
                if (vis[i])
                    continue;
                dfs0(dfs0, i, 0);
                int cur = dfs1(dfs1, i, 0, sum), p1, p2;
                {
                    vector<pair<int, int>> tmp;
                    for (int j : adj[cur])
                        if (!vis[j])
                            tmp.push_back({siz[j], j});
                    sort(tmp.begin(), tmp.end(), greater<>());
                    p1 = tmp[0].second;
                    if (tmp.size() == 1)
                        p2 = cur;
                    else
                        p2 = tmp[1].second;
                }

                dfs2(dfs2, p1, 0);
                auto dep1 = dep;
                dfs2(dfs2, p2, 0);
                auto dep2 = dep;
                cout << "? " << p1 << ' ' << p2 << endl;
                int tmp;
                cin >> tmp;
                for (int j = 1; j <= n; j++)
                {
                    if (vis[j])
                        continue;
                    if (tmp == 0 and dep1[j] >= dep2[j])
                        vis[j] = 1, sum--;
                    else if (tmp == 1 and dep1[j] != dep2[j])
                        vis[j] = 1, sum--;
                    else if (tmp == 2 and dep1[j] <= dep2[j])
                        vis[j] = 1, sum--;
                }
                break;
            }
        }

        for (int i = 1; i <= n; i++)
        {
            if (!vis[i])
            {
                cout << "! " << i << endl;
                break;
            }
        }
    }
}
/*
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
5
0 0
1 5
2 4
0 0
0 0
2
0
2
0 2
0 0
2

output:

? 1 3
? 3 4
! 3
? 1 2
! 2

result:

ok OK (2 test cases)

Test #2:

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

input:

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

output:

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

result:

ok OK (5555 test cases)

Test #3:

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

input:

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

output:

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

result:

ok OK (600 test cases)

Test #4:

score: 0
Accepted
time: 148ms
memory: 14812kb

input:

2
99999
21832 0
77205 0
62668 0
58313 0
14640 0
76941 0
62678 0
8464 0
43145 0
26195 0
46140 0
83205 0
40047 0
81645 0
27077 0
92036 0
14236 0
3576 0
15430 0
75654 0
29049 0
62218 0
83318 0
1116 0
77861 0
9755 0
49236 0
70959 0
62295 0
33580 0
88208 0
55840 0
71061 0
24695 0
88831 0
1891 0
57285 0
9...

output:

? 70790 43991
? 36882 98065
? 17626 87676
? 23816 44703
? 44123 980
? 61196 90504
? 54094 11034
? 63621 34051
? 17588 27981
? 94731 84829
? 34703 56176
? 22424 71333
? 26835 86698
? 46000 29813
? 67 98049
? 67 34703
! 34703
? 44110 46352
? 58000 45037
? 60270 4670
? 26275 82440
? 70127 73169
? 74255...

result:

ok OK (2 test cases)

Test #5:

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

input:

15
3
0 0
1 0
2 0
1
7
6 0
3 0
5 0
0 0
7 0
4 0
1 0
2
2
15
6 0
5 0
1 0
7 0
14 0
11 0
15 0
12 0
2 0
4 0
9 0
13 0
0 0
8 0
3 0
0
0
0
31
3 0
31 0
17 0
23 0
4 0
13 0
1 0
12 0
6 0
0 0
20 0
26 0
14 0
29 0
8 0
25 0
21 0
19 0
5 0
15 0
18 0
10 0
22 0
7 0
28 0
2 0
24 0
30 0
27 0
9 0
16 0
2
0
0
2
63
15 0
62 0
5 0
...

output:

? 1 3
! 2
? 1 5
? 2 5
! 5
? 6 9
? 3 7
? 6 3
! 6
? 29 13
? 2 16
? 12 15
? 2 12
! 12
? 37 8
? 30 14
? 56 55
? 60 29
? 14 29
! 47
? 36 89
? 110 96
? 1 81
? 10 118
? 30 78
? 10 30
! 30
? 233 64
? 68 246
? 28 145
? 30 87
? 232 158
? 142 107
? 145 142
! 145
? 48 439
? 437 468
? 3 274
? 277 285
? 377 125
?...

result:

ok OK (15 test cases)

Test #6:

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

input:

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

output:

? 1 2
! 2
? 1 2
? 1 4
! 1
? 8 3
? 1 2
? 1 8
! 8
? 3 4
? 5 15
? 1 5
? 1 3
! 1
? 12 30
? 11 6
? 1 18
? 15 2
? 1 15
! 15
? 60 3
? 15 63
? 5 54
? 18 39
? 1 5
? 1 18
! 1
? 57 124
? 72 64
? 38 4
? 79 84
? 88 35
? 1 88
? 1 79
! 1
? 90 113
? 91 222
? 57 148
? 232 59
? 221 147
? 31 114
? 1 91
? 1 31
! 1
? 42...

result:

ok OK (16 test cases)

Test #7:

score: 0
Accepted
time: 80ms
memory: 9968kb

input:

15
2
2 0
0 0
2
6
5 0
1 0
6 0
2 0
3 0
0 0
0
2
14
12 0
0 0
11 0
5 0
7 0
1 0
8 0
10 0
14 0
13 0
6 0
9 0
2 0
4 0
0
0
1
30
10 0
29 0
23 0
28 0
9 0
14 0
2 0
30 0
19 0
0 0
15 0
1 0
22 0
8 0
18 0
27 0
7 0
24 0
26 0
3 0
20 0
25 0
6 0
17 0
4 0
12 0
21 0
16 0
13 0
5 0
0
0
0
2
62
24 0
22 0
18 0
17 0
49 0
53 0
3...

output:

? 1 2
! 2
? 1 3
? 1 4
! 4
? 14 5
? 12 6
? 14 12
! 9
? 21 16
? 5 8
? 12 19
? 12 10
! 10
? 60 10
? 9 2
? 36 34
? 24 47
? 9 47
! 52
? 70 84
? 37 90
? 56 58
? 29 116
? 124 117
? 58 117
! 58
? 159 204
? 235 47
? 248 169
? 132 200
? 116 19
? 3 68
? 68 169
! 169
? 359 209
? 139 137
? 75 296
? 260 416
? 32 ...

result:

ok OK (15 test cases)

Test #8:

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

input:

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

output:

? 1 2
! 2
? 3 2
! 2
? 1 2
? 1 3
! 1
? 2 5
? 3 4
! 3
? 1 4
? 5 3
! 5
? 1 4
? 7 3
! 1
? 2 5
? 3 7
? 1 3
! 1
? 1 3
? 1 5
? 4 8
! 8
? 1 4
? 1 10
? 6 9
! 9
? 6 2
? 8 5
? 3 4
! 4
? 1 11
? 1 4
? 4 10
! 10
? 8 13
? 9 13
? 5 6
! 9
? 14 10
? 3 8
? 1 9
! 1
? 14 8
? 2 5
? 11 6
! 6
? 15 7
? 15 14
? 1 15
? 3 11
!...

result:

ok OK (600 test cases)

Test #9:

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

input:

2
99999
0 0
7999 97267
75750 37659
0 0
0 0
33761 92098
90707 18838
13602 27569
0 0
0 0
0 0
0 0
0 0
0 0
0 0
14586 86647
1519 23132
0 0
3430 14643
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
47066 36968
95308 38482
34100 25297
0 0
0 0
0 0
0 0
88902 58991
0 0
0 0
66315 68538
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0...

output:

? 69076 50379
? 11838 79924
? 15463 18079
? 41708 88632
? 63141 40612
? 11131 77076
? 94410 33205
? 38354 72673
? 10499 58250
? 57272 39563
? 6534 79905
? 184 27650
? 81570 32469
? 59500 39276
? 6193 25744
! 25744
? 72481 78976
? 96633 84675
? 2124 81852
? 13836 79494
? 24965 80643
? 78402 74893
? 7...

result:

ok OK (2 test cases)

Test #10:

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

input:

15
3
3 2
0 0
0 0
1
7
0 0
3 6
0 0
7 2
0 0
0 0
5 1
2
2
15
14 12
0 0
0 0
0 0
8 6
10 11
0 0
3 7
2 4
0 0
0 0
0 0
15 5
0 0
9 1
0
0
0
31
4 9
0 0
29 17
0 0
0 0
15 31
5 21
18 14
0 0
0 0
0 0
16 2
12 7
0 0
23 10
0 0
30 13
0 0
24 27
11 26
0 0
0 0
0 0
0 0
19 20
0 0
0 0
0 0
6 25
8 1
28 22
2
0
0
2
63
53 48
40 57
0...

output:

? 3 2
! 1
? 7 2
? 6 3
! 3
? 15 5
? 1 9
? 14 12
! 14
? 17 29
? 6 25
? 31 15
? 22 28
! 28
? 1 2
? 53 48
? 63 19
? 30 56
? 55 59
! 56
? 115 20
? 48 45
? 127 101
? 78 29
? 97 100
? 5 77
! 77
? 140 70
? 206 196
? 135 152
? 147 208
? 84 134
? 246 247
? 54 176
! 54
? 121 60
? 305 71
? 308 106
? 373 473
? 3...

result:

ok OK (15 test cases)

Test #11:

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

input:

16
2
0 0
1 0
2
4
4 2
0 0
0 0
3 0
0
0
8
3 0
0 0
0 0
0 0
1 2
0 0
6 4
5 7
0
0
2
16
16 15
0 0
0 0
0 0
7 11
8 10
0 0
13 0
0 0
0 0
0 0
3 9
0 0
4 2
5 14
6 12
0
1
1
0
32
0 0
22 21
25 18
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
5 10
30 0
1 24
12 31
0 0
0 0
16 8
3 15
11 26
23 14
28 20
6 9
0 0
13 27
0 0
0 0
7 17
0 0
0 ...

output:

? 1 2
! 2
? 1 3
? 1 2
! 1
? 5 7
? 1 2
? 1 3
! 3
? 1 6
? 1 14
? 15 11
? 5 7
! 5
? 32 3
? 21 22
? 28 20
? 7 17
! 7
? 37 58
? 40 19
? 38 30
? 21 42
? 20 64
! 64
? 92 13
? 92 57
? 80 102
? 22 52
? 99 74
? 15 61
! 61
? 245 3
? 245 223
? 150 131
? 242 88
? 179 151
? 75 49
? 11 50
! 75
? 39 511
? 324 57
? ...

result:

ok OK (16 test cases)

Test #12:

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

input:

15
2
0 0
1 0
2
6
6 4
1 5
0 0
0 0
3 0
0 0
0
2
14
0 0
1 7
5 11
13 9
0 0
2 8
0 0
10 0
0 0
0 0
0 0
14 6
0 0
3 4
0
0
2
30
7 0
5 13
0 0
0 0
14 30
15 20
0 0
0 0
3 19
0 0
0 0
11 21
9 1
16 24
0 0
0 0
28 2
8 10
0 0
0 0
0 0
0 0
18 6
0 0
4 29
12 25
0 0
23 26
0 0
27 22
0
2
0
0
62
0 0
0 0
28 47
7 38
0 0
0 0
17 26...

output:

? 1 2
! 2
? 1 5
? 6 4
! 4
? 12 4
? 2 8
? 1 7
! 7
? 17 26
? 13 5
? 30 14
? 22 27
! 22
? 16 57
? 43 36
? 13 20
? 59 23
? 35 45
! 45
? 125 93
? 17 123
? 15 5
? 12 52
? 4 113
? 24 97
! 97
? 241 224
? 112 193
? 88 124
? 30 17
? 242 116
? 44 52
? 13 169
! 44
? 284 376
? 32 30
? 22 406
? 231 379
? 168 464
...

result:

ok OK (15 test cases)

Test #13:

score: 0
Accepted
time: 75ms
memory: 4168kb

input:

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

output:

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

result:

ok OK (600 test cases)

Test #14:

score: 0
Accepted
time: 119ms
memory: 13212kb

input:

2
99999
96748 53986
34197 77552
29863 63559
79099 26449
45078 1051
0 0
27416 4135
0 0
38606 81189
93892 68603
48776 185
79602 18311
51243 83678
89044 40032
28883 35663
0 0
0 0
21603 15821
0 0
51448 75971
70275 8326
0 0
0 0
57049 72937
3297 94939
0 0
59258 39159
3205 34675
54876 24769
0 0
0 0
0 0
851...

output:

? 96970 71188
? 6820 87538
? 59029 32876
? 46360 20365
? 49372 9490
? 51870 93805
? 96975 74496
? 13426 43271
? 71402 87378
? 76304 16502
? 25757 70459
? 82241 80115
? 32056 76905
? 13090 1407
? 82241 13090
? 13090 41809
! 13090
? 50499 6749
? 42167 37781
? 96466 36486
? 37783 33496
? 48920 28303
? ...

result:

ok OK (2 test cases)

Test #15:

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

input:

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

output:

? 1 3
! 2
? 2 5
? 1 7
! 2
? 15 4
? 1 15
? 11 2
! 1
? 1 14
? 18 10
? 10 29
? 13 30
! 13
? 38 44
? 1 42
? 2 9
? 2 34
? 5 23
! 5
? 31 51
? 96 62
? 8 100
? 52 89
? 52 82
? 57 70
! 82
? 122 124
? 102 162
? 84 231
? 110 135
? 147 223
? 3 236
? 80 201
! 201
? 322 266
? 414 146
? 335 72
? 66 306
? 76 89
? 8...

result:

ok OK (15 test cases)

Test #16:

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

input:

16
2
0 0
1 0
2
4
0 0
1 0
4 2
0 0
0
0
8
0 0
0 0
0 0
3 5
8 6
2 0
1 4
0 0
0
0
2
16
0 0
7 8
0 0
1 2
0 0
0 0
0 0
5 10
3 0
12 16
14 13
0 0
15 4
0 0
0 0
6 9
0
0
0
0
32
26 17
5 31
28 25
18 7
0 0
0 0
14 12
15 0
22 4
0 0
29 1
19 2
0 0
0 0
0 0
6 8
10 21
0 0
0 0
0 0
13 3
0 0
0 0
0 0
32 30
0 0
20 9
0 0
0 0
23 16...

output:

? 1 2
! 2
? 2 4
? 1 2
! 1
? 4 6
? 7 3
? 1 7
! 7
? 2 10
? 4 11
? 4 7
? 1 4
! 1
? 1 31
? 3 30
? 17 3
? 1 10
? 1 26
! 26
? 56 43
? 11 18
? 52 47
? 17 52
? 1 44
? 1 38
! 1
? 38 43
? 17 53
? 117 69
? 113 45
? 107 113
? 117 30
? 1 117
! 1
? 133 170
? 75 121
? 14 197
? 1 90
? 3 103
? 212 3
? 1 190
? 1 245
...

result:

ok OK (16 test cases)

Test #17:

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

input:

15
2
0 0
1 0
2
6
0 0
5 0
1 2
0 0
0 0
4 3
1
2
14
8 14
0 0
0 0
0 0
0 0
12 11
10 0
0 0
2 7
0 0
4 1
0 0
3 6
5 9
0
1
1
30
29 21
6 9
0 0
0 0
0 0
0 0
0 0
19 17
24 30
0 0
14 26
23 0
0 0
0 0
25 18
0 0
7 20
16 12
0 0
13 11
28 8
10 15
0 0
0 0
0 0
3 22
5 2
0 0
0 0
4 1
0
0
2
0
62
0 0
34 33
0 0
0 0
0 0
37 45
0 0
...

output:

? 1 2
! 2
? 1 6
? 5 3
! 3
? 14 11
? 2 14
? 10 9
! 7
? 8 20
? 1 9
? 1 8
? 8 19
! 8
? 59 42
? 31 12
? 19 40
? 12 40
? 40 47
! 47
? 17 40
? 11 102
? 110 119
? 61 66
? 61 40
? 40 43
! 40
? 189 90
? 221 158
? 156 74
? 166 228
? 112 142
? 158 142
? 142 222
! 142
? 192 60
? 285 44
? 327 25
? 280 213
? 67 7...

result:

ok OK (15 test cases)

Test #18:

score: 0
Accepted
time: 132ms
memory: 11184kb

input:

2
99999
0 0
88119 0
72740 0
6901 19702
0 0
10620 84889
0 0
9552 63972
45156 60768
9152 72379
0 0
59875 97207
48193 0
17282 54916
65927 27713
80083 15817
36966 75381
0 0
77279 56298
0 0
11554 61779
0 0
89976 0
65282 42151
95206 62876
97329 86772
0 0
0 0
0 0
11820 0
0 0
20432 0
50520 39907
0 0
46948 1...

output:

? 52174 35226
? 26122 16093
? 61873 11494
? 91694 11494
? 33972 90037
? 21572 90037
? 51091 91442
? 93596 7067
? 75096 14316
? 75096 55875
? 42793 96805
? 59747 42793
? 472 67072
? 59747 64770
! 92650
? 91773 80592
? 80592 50906
? 73367 65219
? 33796 20489
? 61722 74041
? 74041 35779
? 51748 35779
?...

result:

ok OK (2 test cases)

Test #19:

score: 0
Accepted
time: 234ms
memory: 3756kb

input:

100000
2
0 0
0 1
2
2
0 0
0 1
0
2
0 0
0 1
2
2
0 0
0 1
0
2
0 0
0 1
2
2
0 0
0 1
0
2
0 0
0 1
0
2
0 0
0 1
0
2
0 0
0 1
0
2
0 0
0 1
2
2
0 0
0 1
0
2
0 0
0 1
0
2
0 0
0 1
2
2
0 0
0 1
2
2
0 0
0 1
0
2
0 0
0 1
2
2
0 0
0 1
2
2
0 0
0 1
2
2
0 0
0 1
2
2
0 0
0 1
0
2
0 0
0 1
0
2
0 0
0 1
0
2
0 0
0 1
2
2
0 0
0 1
0
2
0 0...

output:

? 1 2
! 2
? 1 2
! 1
? 1 2
! 2
? 1 2
! 1
? 1 2
! 2
? 1 2
! 1
? 1 2
! 1
? 1 2
! 1
? 1 2
! 1
? 1 2
! 2
? 1 2
! 1
? 1 2
! 1
? 1 2
! 2
? 1 2
! 2
? 1 2
! 1
? 1 2
! 2
? 1 2
! 2
? 1 2
! 2
? 1 2
! 2
? 1 2
! 1
? 1 2
! 1
? 1 2
! 1
? 1 2
! 2
? 1 2
! 1
? 1 2
! 1
? 1 2
! 2
? 1 2
! 2
? 1 2
! 2
? 1 2
! 2
? 1 2
! 2
...

result:

ok OK (100000 test cases)

Extra Test:

score: 0
Extra Test Passed