QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#702996#5088. Two Choreographiestamthegod#WA 1925ms40088kbC++234.2kb2024-11-02 16:56:212024-11-02 16:56:21

Judging History

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

  • [2024-11-02 16:56:21]
  • 评测
  • 测评结果:WA
  • 用时:1925ms
  • 内存:40088kb
  • [2024-11-02 16:56:21]
  • 提交

answer

#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n;
vector<int> adj[maxN];
int jump[maxN][20];
int depth[maxN];
pair<int, int> edge[maxN];
int mark[maxN];
void ReadInput()
{
    cin >> n;
    for(int i=1; i<=2*n-3; i++)
    {
        int u, v;
        cin >> u >> v;
        edge[i] = {u, v};
    }
}
void dfs(int u, int par)
{
    for(int v : adj[u])
    {
        if(v == par) continue;
        jump[v][0] = u;
        depth[v] = depth[u] + 1;
        for(int i=1; i<=18; i++)
            jump[v][i] = jump[jump[v][i - 1]][i - 1];
        dfs(v, u);
    }
}
int lca(int u, int v)
{
    if(depth[u] < depth[v]) swap(u, v);
    int k = depth[u] - depth[v];
    for(int i=18; i>=0; i--)
        if(k >> i & 1) u = jump[u][i];
    if(u == v) return u;
    for(int i=18; i>=0; i--)
        if(jump[u][i] != jump[v][i])
        {
            u = jump[u][i];
            v = jump[v][i];
        }
    return jump[u][0];
}
int dist(int u, int v)
{
    return depth[u] + depth[v] - 2 * depth[lca(u, v)];
}
int lab[maxN];
int findset(int u)
{
    return lab[u] < 0 ? u : lab[u] = findset(lab[u]);
}
int unite(int u, int v)
{
    int r = findset(u), s = findset(v);
    if(r == s) return false;
    if(lab[r] < lab[s]) swap(r, s);
    lab[r] += lab[s];
    lab[s] = r;
    return true;
}
vector<int> go(int x, int y)
{
    vector<int> vc1, vc2;
    int t = lca(x, y);
    while(x != t)
    {
        vc1.pb(x);
        x = jump[x][0];
    }
    while(y != t)
    {
        vc2.pb(y);
        y = jump[y][0];
    }
    vc2.pb(t);
    reverse(vc2.begin(), vc2.end());
    vector<int> res;
    for(int v : vc1)
        res.pb(v);
    for(int v : vc2)
        res.pb(v);
    return res;
    for(int v : vc1)
        cout << v << " ";
    for(int v : vc2)
        cout << v << " ";
    cout << '\n';
}
void print(int x, int y, int res)
{
    vector<int> path1 = go(edge[x].fi, edge[x].se);
    vector<int> path2 = go(edge[y].fi, edge[y].se);
    vector<int> vc1 = path1, vc2 = path2;
    sort(vc1.begin(), vc1.end());
    sort(vc2.begin(), vc2.end());
    vc1.erase(unique(vc1.begin(), vc1.end()), vc1.end());
    vc2.erase(unique(vc2.begin(), vc2.end()), vc2.end());
    if(res < 3) while(true);
  //  if(vc1 == vc2 || vc1.size() != vc2.size() || vc1.size() != res) while(true);
    cout << res << '\n';
    for(int v : path1) cout << v << " ";
    cout << '\n';
    for(int v : path2)
        cout << v << " ";
    cout << '\n';
   // go(edge[x].fi, edge[x].se);
    //go(edge[y].fi, edge[y].se);
}
void Solve()
{
    while(true)
    {
        shuffle(edge + 1, edge + 2 * n - 2, rng);
        fill(lab, lab + n + 1, -1);
        for(int i=1; i<=n; i++)
            adj[i].clear();
        fill(mark, mark + 2 * n + 4, 0);
        for(int i=1; i<=2*n-3; i++)
        {
            if(unite(edge[i].fi, edge[i].se))
            {
                adj[edge[i].fi].pb(edge[i].se);
                adj[edge[i].se].pb(edge[i].fi);
                mark[i] = 1;
            }
        }
        dfs(1, 0);
        map<int, int> mp;
        for(int i=1; i<=2*n-3; i++)
        {
            if(mark[i]) continue;
            int len = dist(edge[i].fi, edge[i].se) + 1;
            if(len <= 2) continue;
            if(mp[len])
            {
                print(mp[len], i, len);
                return;
            }
            mp[len] = i;
        }
        if(1.0 * clock() / CLOCKS_PER_SEC > 2.2)
        {
            cout << -1;
            return;
        }
    }
}
#define taskname "sol"
int32_t main()
{
    if (fopen(taskname ".inp", "r"))
    {
        freopen(taskname ".inp", "r", stdin);
        //freopen(taskname ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    //cin >> T;
    for(int itest=1; itest<=T; itest++)
    {
        ReadInput();
        Solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 2
1 3
1 4
2 3
2 4

output:

3
1 2 3 
2 1 4 

result:

ok 

Test #2:

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

input:

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

output:

3
2 1 3 
3 1 4 

result:

ok 

Test #3:

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

input:

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

output:

4
3 6 5 4 
5 6 1 2 

result:

ok 

Test #4:

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

input:

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

output:

3
19 1 16 
36 1 16 

result:

ok 

Test #5:

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

input:

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

output:

4
82 114 48 50 
34 159 185 31 

result:

ok 

Test #6:

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

input:

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

output:

43
7815 2356 996 87 2455 2973 3810 140 7498 143 7741 2344 3714 7894 3680 4919 4674 790 7604 6441 3589 459 6808 7605 2289 2690 4549 2027 5911 3930 5149 561 2806 2917 5953 5978 1437 2240 3104 74 4068 6775 6442 
2670 2539 7065 1167 2099 3273 6700 4778 1338 7752 523 7427 3205 3828 790 4674 4919 3680 789...

result:

ok 

Test #7:

score: 0
Accepted
time: 33ms
memory: 38400kb

input:

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

output:

133
95611 14453 43444 3881 69040 11900 16972 3695 60901 53947 34913 40085 93462 65432 45517 67340 68892 92974 73781 76666 79854 19765 30084 5224 51336 53843 7985 35845 67329 93638 81860 53861 90498 52053 12042 7470 80272 39771 65457 11289 44781 13540 45911 90066 35402 59932 84577 15107 48496 14665 6...

result:

ok 

Test #8:

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

input:

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

output:

85
41659 2348 38911 62926 55407 67307 14691 35479 74760 8251 87556 89966 39939 54768 83101 44639 52905 3743 21317 59013 85302 62820 21692 86294 34056 98728 75802 6024 19926 65821 76992 30348 30728 19113 82267 42688 71540 71180 39578 93596 6398 79693 83842 21318 89605 29884 36780 93416 17002 81532 16...

result:

ok 

Test #9:

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

input:

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

output:

4
1 7 3 4 
1 7 5 6 

result:

ok 

Test #10:

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

input:

100000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 5...

output:

4
1 79515 100000 87704 
100000 79515 1 39580 

result:

ok 

Test #11:

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

input:

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

output:

3
3 8 4 
2 8 3 

result:

ok 

Test #12:

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

input:

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

output:

4
3 2 9 4 
1 9 2 3 

result:

ok 

Test #13:

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

input:

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

output:

3
9 1 10 
1 10 6 

result:

ok 

Test #14:

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

input:

1000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
...

output:

4
1 228 1000 389 
1000 228 1 221 

result:

ok 

Test #15:

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

input:

9999
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
...

output:

4
1 3640 9999 6861 
1 3640 9999 5897 

result:

ok 

Test #16:

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

input:

10000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

4
1 2453 10000 7972 
1 2453 10000 4491 

result:

ok 

Test #17:

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

input:

94753
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

4
94753 8404 1 45503 
1 8404 94753 16286 

result:

ok 

Test #18:

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

input:

99999
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

4
99999 28426 1 51382 
1 28426 99999 38266 

result:

ok 

Test #19:

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

input:

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

output:

3
6 1 7 
1 4 3 

result:

ok 

Test #20:

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

input:

100000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 5...

output:

3
60800 1 60801 
1 4027 4028 

result:

ok 

Test #21:

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

input:

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

output:

3
1 7 8 
1 7 6 

result:

ok 

Test #22:

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

input:

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

output:

3
1 7 6 
7 1 8 

result:

ok 

Test #23:

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

input:

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

output:

3
1 8 7 
3 1 4 

result:

ok 

Test #24:

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

input:

1000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
...

output:

3
1 114 115 
292 1 293 

result:

ok 

Test #25:

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

input:

9999
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
...

output:

3
1 479 480 
3771 1 3772 

result:

ok 

Test #26:

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

input:

10000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

3
1 5975 5976 
6420 1 6421 

result:

ok 

Test #27:

score: 0
Accepted
time: 33ms
memory: 38788kb

input:

97065
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

3
29926 1 29927 
14118 1 14119 

result:

ok 

Test #28:

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

input:

99999
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

3
54605 1 54606 
1 80549 80548 

result:

ok 

Test #29:

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

input:

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

output:

3
6 5 7 
7 5 4 

result:

ok 

Test #30:

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

input:

100000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 5...

output:

3
100000 35724 35723 
100000 615 614 

result:

ok 

Test #31:

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

input:

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

output:

4
8 4 3 2 
4 8 6 5 

result:

ok 

Test #32:

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

input:

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

output:

3
1 9 2 
5 9 6 

result:

ok 

Test #33:

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

input:

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

output:

3
10 3 2 
9 8 10 

result:

ok 

Test #34:

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

input:

1000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
...

output:

3
1000 637 636 
1000 554 553 

result:

ok 

Test #35:

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

input:

9999
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
...

output:

3
5794 9999 5795 
9999 5950 5951 

result:

ok 

Test #36:

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

input:

10000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

3
5666 10000 5667 
1557 10000 1558 

result:

ok 

Test #37:

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

input:

92892
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

3
92892 48026 48025 
92892 26886 26885 

result:

ok 

Test #38:

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

input:

99999
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

3
99999 14622 14621 
3748 99999 3749 

result:

ok 

Test #39:

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

input:

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

output:

4
2 1 5 8 
5 8 7 6 

result:

ok 

Test #40:

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

input:

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

output:

3
4 10 3 
5 10 4 

result:

ok 

Test #41:

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

input:

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

output:

37
818 921 868 265 264 113 114 115 116 580 947 55 994 995 313 979 992 105 511 510 401 296 756 755 292 544 543 644 803 802 801 800 738 903 71 70 38 
224 223 222 119 534 674 675 454 455 456 2 303 317 316 822 635 636 645 644 543 544 292 755 756 296 401 510 511 105 992 979 313 995 994 55 356 241 

result:

ok 

Test #42:

score: 0
Accepted
time: 7ms
memory: 14664kb

input:

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

output:

30
4539 2322 2139 2138 5198 9559 1013 1014 1015 2395 2394 6139 3081 7198 7197 7196 5337 5336 5335 7115 7114 4312 4313 4314 6326 594 595 9425 6877 4538 
7994 7995 2602 7733 374 9836 2340 1359 8930 8931 488 4153 6002 7727 7726 7725 9718 2039 2040 2041 2042 1672 4800 9684 9683 5086 3208 2861 2862 8158 

result:

ok 

Test #43:

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

input:

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

output:

20
8005 8004 8003 8376 8097 8098 7577 4913 6512 299 300 301 302 4588 4589 4728 8273 8272 4154 8341 
7811 7812 4575 4574 4050 1279 1278 300 299 6512 4913 7577 8098 8097 1964 9139 8742 4161 4162 2953 

result:

ok 

Test #44:

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

input:

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

output:

4
61784 61783 61782 8414 
20764 1834 60862 60861 

result:

ok 

Test #45:

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

input:

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

output:

65
1540 40136 62801 62802 56814 28591 65978 65977 65976 65975 43932 88264 74113 74114 74115 88320 88321 79121 81046 19773 52676 52675 1568 35704 35703 26292 17204 16883 16882 96642 43644 43645 18273 88689 87511 81618 71513 13019 13020 56924 71895 71894 72723 72724 6429 6430 82707 82706 57056 57057 5...

result:

ok 

Test #46:

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

input:

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

output:

112
40511 40512 89125 99191 99192 40786 75543 45251 92789 77205 77204 29950 5124 7553 7552 64652 42837 42838 59269 59270 53004 69053 54886 45273 85201 17490 50683 52719 6467 6466 6465 35527 5160 24841 92457 92456 95294 95293 92689 30822 30821 43397 35798 44834 60758 60757 90128 16440 94829 94828 765...

result:

ok 

Test #47:

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

input:

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

output:

90
79902 70932 70931 67752 49789 49788 87814 15012 15013 15014 7017 91900 91899 23827 79208 79209 77357 78752 78751 8141 8142 57654 57655 18725 18726 56385 56386 56387 1890 1889 10618 64809 64810 75009 71400 71401 71402 44918 9729 28441 28442 8638 75150 75149 78822 32804 32803 4986 4985 4984 68654 6...

result:

ok 

Test #48:

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

input:

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

output:

67
44098 27139 27140 60536 60535 60534 60533 60532 70671 33937 62625 8111 66892 55170 76734 76735 59275 59276 19306 19307 19308 16015 16016 16017 79611 79612 91103 91102 50895 71697 23117 35117 28977 64953 37595 4833 56388 56387 56386 96869 33217 64151 16236 16237 40690 40691 40692 21059 21060 88843...

result:

ok 

Test #49:

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

input:

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

output:

85
46687 46688 74595 74596 88708 21404 60749 60750 32684 58248 6883 43173 43174 83282 83283 11864 76557 76558 2467 19609 48525 71900 71901 32463 25057 25943 39159 39158 14949 14948 25511 25512 90401 12242 12241 12240 22229 37563 6600 6601 70836 20345 20346 47306 47307 47308 15210 25879 78732 46242 6...

result:

ok 

Test #50:

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

input:

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

output:

5
1 2 3 7 5 
6 2 3 7 5 

result:

ok 

Test #51:

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

input:

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

output:

123
74578 69573 69572 69571 50775 50774 61610 61611 24731 24730 9248 47244 47245 55220 97795 45355 38010 38009 71110 71111 57589 57590 57591 83207 97430 97431 47823 51722 51723 71595 85827 85828 47693 51230 61984 41945 41946 84342 62204 62205 1220 86300 86299 86298 80045 29342 58441 58442 23354 1945...

result:

ok 

Test #52:

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

input:

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

output:

4
6 1 2 5 
3 2 5 4 

result:

ok 

Test #53:

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

input:

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

output:

3
9 6 8 
6 8 7 

result:

ok 

Test #54:

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

input:

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

output:

3
1 9 2 
1 9 8 

result:

ok 

Test #55:

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

input:

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

output:

5
3 2 7 8 4 
6 7 8 4 5 

result:

ok 

Test #56:

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

input:

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

output:

4
6 7 8 9 
4 7 6 1 

result:

ok 

Test #57:

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

input:

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

output:

3
2 6 5 
8 6 7 

result:

ok 

Test #58:

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

input:

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

output:

4
4 5 1 3 
4 5 1 2 

result:

ok 

Test #59:

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

input:

4
1 2
4 1
4 3
3 1
4 2

output:

3
1 4 2 
4 1 3 

result:

ok 

Test #60:

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

input:

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

output:

3
1 8 3 
5 9 10 

result:

ok 

Test #61:

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

input:

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

output:

28
895 313 160 659 719 885 602 170 764 989 375 639 199 40 324 299 384 646 22 236 856 773 549 500 36 853 385 172 
699 842 903 895 313 160 659 719 885 602 170 764 989 375 639 199 40 324 299 384 646 22 713 376 202 793 554 993 

result:

ok 

Test #62:

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

input:

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

output:

36
1244 8673 7230 8879 3076 3749 8706 319 1880 7357 7461 1224 6725 2353 5609 5848 8605 3976 2361 8824 1909 2638 9449 6987 7550 4394 4092 9147 9930 9203 6181 6111 8961 1979 6235 7733 
8483 9197 1812 6452 789 1413 7461 1224 6725 2353 5609 5848 8605 3976 2361 8824 1909 2638 9449 6987 7550 4394 4092 914...

result:

ok 

Test #63:

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

input:

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

output:

38
6153 7642 2627 7707 1966 7035 7331 6727 290 4962 8767 5683 7007 3651 322 9012 9953 2516 7724 776 6624 6470 1502 3451 3516 134 4241 4749 9423 3580 8686 4649 5442 8805 1860 6813 2450 1869 
1525 6565 5487 1929 1097 3146 6093 3694 2599 185 2183 6813 1860 8805 5442 4649 8686 3580 9423 4749 4241 134 35...

result:

ok 

Test #64:

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

input:

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

output:

188
24269 79951 51011 30513 10010 57691 92440 40584 77800 15236 10686 74654 39558 69438 46560 30986 84511 48073 76446 92240 95905 49610 96227 45396 50341 1959 323 1841 95059 86744 37255 7571 68329 94722 40950 58877 370 34950 35926 10238 74245 39150 73439 84781 19365 56706 30010 75815 26032 2774 2522...

result:

ok 

Test #65:

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

input:

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

output:

66
11683 49012 86653 84449 67967 52999 73071 62245 60939 7720 14851 54794 13753 69939 27936 18672 84170 74999 24137 77648 79973 38064 26416 74062 45729 66528 32160 28822 17727 56234 66546 50016 58919 28224 87359 32942 16526 15513 84721 53641 26346 44877 40414 29997 41395 49340 39300 59512 73666 3229...

result:

ok 

Test #66:

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

input:

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

output:

139
59203 250 67423 30602 39846 30904 25463 32596 23970 72050 69549 97255 8200 21611 36564 58847 42041 58094 41545 35381 61054 53279 16955 401 45915 9148 31781 57344 43216 22725 92537 25908 57860 88770 28818 75967 33964 85584 5500 84483 40234 41516 41369 52120 39385 21733 82025 31273 7083 14912 8219...

result:

ok 

Test #67:

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

input:

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

output:

51
45138 11753 60111 3170 86904 5447 74467 47452 44955 84928 5982 55402 12139 37148 80792 34965 44635 2895 54922 81588 64189 27016 57917 96572 27088 75014 76972 99213 46575 96311 58625 17872 34841 58714 14417 80828 47103 74695 94345 34210 80055 82430 4159 56207 4323 59081 33138 87697 78587 22238 299...

result:

ok 

Test #68:

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

input:

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

output:

137
24104 52735 69759 49110 29590 84853 15606 31291 22077 63638 79121 79031 28856 45738 45482 11634 34767 58521 62284 88878 14105 82665 74418 26845 48413 94489 43337 91826 19922 38406 99363 38876 2719 98048 61470 46552 7417 13163 6530 74497 37556 83803 38387 85127 57156 91493 30249 15788 2234 62936 ...

result:

ok 

Test #69:

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

input:

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

output:

48
54809 52106 54513 14099 13144 19376 9894 56541 46824 73136 7924 7144 74973 51556 66195 33122 53036 16137 403 21895 23190 65471 47856 54869 7290 80880 1646 60526 51239 4099 62518 19081 76085 91458 36714 85493 93996 2329 25544 4716 12186 71983 42464 46110 57567 4258 34988 7715 
56315 6546 52944 527...

result:

ok 

Test #70:

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

input:

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

output:

4
2 3 5 4 
5 3 2 1 

result:

ok 

Test #71:

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

input:

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

output:

163
9228 31558 32672 41794 59870 5527 68752 10601 28336 39965 51965 83098 76862 84049 69889 81632 93076 24838 57771 17616 54295 75845 33520 22527 10889 14784 68438 43675 88293 46796 27889 45327 80197 29413 20286 34273 18542 18594 67208 27683 70239 51042 93200 81544 82468 79020 1087 64806 59908 31938...

result:

ok 

Test #72:

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

input:

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

output:

3
3 1 2 
5 6 3 

result:

ok 

Test #73:

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

input:

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

output:

3
1 3 6 
7 3 1 

result:

ok 

Test #74:

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

input:

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

output:

4
1 6 7 4 
5 7 6 1 

result:

ok 

Test #75:

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

input:

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

output:

4
8 9 2 5 
2 9 8 4 

result:

ok 

Test #76:

score: -100
Wrong Answer
time: 1925ms
memory: 7988kb

input:

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

output:

-1

result:

wrong answer Integer -1 violates the range [3, 10]