QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#702971#5088. Two Choreographiestamthegod#TL 46ms41024kbC++234.1kb2024-11-02 16:53:132024-11-02 16:53:15

Judging History

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

  • [2024-11-02 16:53:15]
  • 评测
  • 测评结果:TL
  • 用时:46ms
  • 内存:41024kb
  • [2024-11-02 16:53:13]
  • 提交

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;
        }
    }
}
#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: 0ms
memory: 9724kb

input:

4
1 2
1 3
1 4
2 3
2 4

output:

3
2 1 3 
2 1 4 

result:

ok 

Test #2:

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

input:

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

output:

3
3 1 4 
1 3 2 

result:

ok 

Test #3:

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

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:

3
2 1 6 
5 1 6 

result:

ok 

Test #4:

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

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
1 40 16 
13 4 2 

result:

ok 

Test #5:

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

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:

3
11 136 193 
109 48 119 

result:

ok 

Test #6:

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

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:

25
2440 5604 1628 3104 6648 3348 6100 5237 1528 7555 3428 1054 3464 275 6084 1042 1758 5258 6715 1559 3038 4454 1769 3805 5370 
2455 2973 2006 2378 2026 5771 7641 7242 3931 1704 2522 436 4995 602 399 7093 2064 2152 7844 984 7397 6087 6452 5043 87 

result:

ok 

Test #7:

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

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:

20
25812 59687 50079 77166 17251 71684 47399 82872 26047 11971 42758 71588 31820 35054 96215 16009 45717 92125 88312 88238 
99093 3286 6023 13326 38683 10649 87211 82047 63451 23214 45865 43078 49524 8702 11118 67569 49089 7189 57527 55988 

result:

ok 

Test #8:

score: 0
Accepted
time: 30ms
memory: 40040kb

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:

4
64393 90675 10184 16292 
88141 40464 9098 69187 

result:

ok 

Test #9:

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

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
7 3 4 5 
1 7 3 2 

result:

ok 

Test #10:

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

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
100000 63794 1 88853 
1 63794 100000 58148 

result:

ok 

Test #11:

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

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
8 3 2 
8 1 4 

result:

ok 

Test #12:

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

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:

3
4 9 5 
1 2 3 

result:

ok 

Test #13:

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

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
10 1 4 
9 1 10 

result:

ok 

Test #14:

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

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
1000 364 1 442 
1000 364 1 518 

result:

ok 

Test #15:

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

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
9999 3948 1 588 
1 3948 9999 7802 

result:

ok 

Test #16:

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

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
10000 7377 1 5352 
1 7377 10000 8012 

result:

ok 

Test #17:

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

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
1 87245 94753 13393 
94753 87245 1 30009 

result:

ok 

Test #18:

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

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 82491 1 16186 
1 82491 99999 55069 

result:

ok 

Test #19:

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

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
1 4 5 
1 2 3 

result:

ok 

Test #20:

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

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
1 48026 48025 
1 73266 73267 

result:

ok 

Test #21:

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

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: 9720kb

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
2 1 3 
1 7 8 

result:

ok 

Test #23:

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

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
6 1 7 
1 4 3 

result:

ok 

Test #24:

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

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 589 588 
1 127 126 

result:

ok 

Test #25:

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

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 9631 9630 
7893 1 7894 

result:

ok 

Test #26:

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

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 6468 6469 
1 737 738 

result:

ok 

Test #27:

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

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
1 27461 27460 
1 27445 27446 

result:

ok 

Test #28:

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

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
77637 1 77638 
1 49846 49845 

result:

ok 

Test #29:

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

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
7 1 2 
7 5 4 

result:

ok 

Test #30:

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

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 25787 25788 
100000 46347 46346 

result:

ok 

Test #31:

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

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:

3
8 6 5 
6 8 7 

result:

ok 

Test #32:

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

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
9 8 7 
9 1 2 

result:

ok 

Test #33:

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

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 4 3 
10 7 8 

result:

ok 

Test #34:

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

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 363 362 
1000 577 576 

result:

ok 

Test #35:

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

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
9999 4613 4612 
9999 339 338 

result:

ok 

Test #36:

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

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
10000 1454 1455 
10000 6562 6563 

result:

ok 

Test #37:

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

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 47925 47926 
92892 24759 24760 

result:

ok 

Test #38:

score: 0
Accepted
time: 30ms
memory: 41024kb

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
11991 99999 11992 
99999 2926 2925 

result:

ok 

Test #39:

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

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
7 6 5 8 
2 8 5 6 

result:

ok 

Test #40:

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

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
5 10 4 
3 4 10 

result:

ok 

Test #41:

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

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:

17
682 681 680 679 193 771 770 938 476 475 743 744 882 881 709 710 711 
83 82 81 80 224 447 828 650 487 486 633 563 562 561 512 511 510 

result:

ok 

Test #42:

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

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:

22
7789 1051 1052 4995 4996 9809 9810 7877 7878 651 7450 1180 1181 2182 2269 7215 9631 9630 1762 1761 5687 8104 
9907 9906 9699 9700 9701 6393 4571 7748 3032 3145 3146 3147 3965 3964 3963 3723 3166 3165 4814 2712 4204 389 

result:

ok 

Test #43:

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

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:

33
8762 8763 8764 8765 3966 8448 6220 6221 6222 8752 5238 5237 5236 8707 1678 5716 9199 9200 4890 7262 5678 5677 1877 9132 9409 8903 8904 8905 5421 1337 1338 1339 8761 
847 848 849 2724 2228 9129 9128 4639 6356 6357 6673 6674 6675 8899 8753 8187 2391 2390 2389 1474 5324 7370 7369 1884 1885 1351 1352...

result:

ok 

Test #44:

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

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:

101
92005 40197 74420 74421 31846 87188 59934 33306 33307 75631 45468 45739 59258 5871 88404 48066 48067 413 412 58092 58093 82582 41474 41475 77872 6966 38840 38839 7871 76405 76404 93835 93836 93837 93838 93839 59805 37924 37923 25765 23983 23984 23985 65235 51516 18512 18513 18514 18515 32557 611...

result:

ok 

Test #45:

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

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:

203
29800 29801 61459 39476 22277 48127 55097 55096 2393 18471 18472 28694 59918 59917 59916 89077 89076 89075 36684 13182 64508 45149 38084 38085 38086 61011 38668 38669 37353 37354 94971 85505 85506 8274 93404 93405 35469 65602 89872 77105 18584 18583 22415 52188 77476 90874 90873 60290 16263 1626...

result:

ok 

Test #46:

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

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:

99
44595 6990 6989 8756 46817 49419 69659 34044 10016 18335 18334 35893 35894 35895 63137 63138 80673 80672 22536 22535 22534 14719 79258 79257 14207 50025 50026 55232 55231 55230 38959 38960 52207 75411 32992 32993 32994 32995 29387 29388 31398 59858 58628 58629 32629 32630 94861 46868 99656 9689 1...

result:

ok 

Test #47:

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

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:

53
6111 52856 62348 15301 99770 99771 99772 4145 4144 4143 9079 9080 43001 43000 42999 25308 17129 17128 19707 19706 19705 31518 31517 98049 96469 96470 96471 25611 82370 82369 82368 1757 66507 9782 42741 731 78891 78892 5337 5338 62247 62248 78282 78281 78280 15155 15156 15157 15158 92850 74695 209...

result:

ok 

Test #48:

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

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:

4
46445 97864 57652 46446 
96124 96125 96126 96123 

result:

ok 

Test #49:

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

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:

4
92611 92612 7390 83951 
81439 59758 70764 55141 

result:

ok 

Test #50:

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

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:

4
1 2 7 5 
6 2 7 5 

result:

ok 

Test #51:

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

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:

269
64904 39710 39709 44586 44585 97987 8319 8320 73187 73188 85133 7700 68918 66978 98985 96174 96173 55838 55837 55982 55983 47947 92428 92429 62380 6965 12852 12851 65159 57963 80937 80938 82967 82966 64529 10176 88237 88238 25539 3932 3933 81720 81719 81718 6426 39118 39117 52617 60399 68896 688...

result:

ok 

Test #52:

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

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:

3
5 4 2 
3 2 4 

result:

ok 

Test #53:

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

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 1 4 
6 8 7 

result:

ok 

Test #54:

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

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
7 6 5 
8 1 9 

result:

ok 

Test #55:

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

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:

3
8 4 9 
6 5 4 

result:

ok 

Test #56:

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

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
1 4 5 2 
3 2 5 4 

result:

ok 

Test #57:

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

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:

4
1 4 5 2 
8 9 3 4 

result:

ok 

Test #58:

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

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:

5
1 9 7 6 5 
3 1 9 7 6 

result:

ok 

Test #59:

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

input:

4
1 2
4 1
4 3
3 1
4 2

output:

3
1 4 2 
3 4 1 

result:

ok 

Test #60:

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

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
5 6 10 
1 3 9 

result:

ok 

Test #61:

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

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:

17
15 55 899 671 570 249 945 841 484 630 641 585 469 538 571 439 331 
937 86 976 732 943 779 630 484 841 945 249 570 374 478 528 7 387 

result:

ok 

Test #62:

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

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:

4
6545 2499 8256 4895 
5106 7318 8748 5567 

result:

ok 

Test #63:

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

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:

19
1728 530 5726 7664 2945 624 4692 4105 7823 2137 5401 5645 2302 2849 2650 2264 4133 4993 7820 
9108 9644 9585 313 3666 8992 7198 3675 8717 1849 689 8002 9680 6541 2311 5227 8901 5030 365 

result:

ok 

Test #64:

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

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:

163
96355 7982 44743 10786 5556 86356 44242 9393 86751 41338 38091 37429 26561 74092 95922 80093 8296 52434 18941 74364 26414 92354 63376 87518 49833 13845 18082 25872 7554 98112 4544 39236 72061 73912 5084 67390 94455 21188 84045 48509 69718 25357 45244 66452 58710 52912 82499 29864 80784 10075 830...

result:

ok 

Test #65:

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

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:

4
61962 42524 23417 46630 
80053 61253 1268 29330 

result:

ok 

Test #66:

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

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:

31
74339 39508 54226 56094 88598 52227 86375 47231 27369 26720 73937 39334 13829 22272 37216 5359 31260 46472 55027 1311 88210 2702 69636 94370 15318 75848 76387 75830 54244 73449 94380 
73237 1523 40603 24664 71433 11495 75050 36122 47423 71790 47027 50298 81202 91608 56100 89073 45925 97747 2594 2...

result:

ok 

Test #67:

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

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:

133
34567 57804 83671 6361 16169 43068 27293 87061 31156 81404 54222 64231 19678 24161 61873 27329 48153 56096 57961 92274 98938 48230 34551 12495 88365 82905 47786 76813 94052 95371 49793 12420 77248 78850 11295 58569 52807 49273 56115 73645 19990 97683 47661 88219 47775 30952 42305 75959 39509 384...

result:

ok 

Test #68:

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

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:

26
72902 49593 47547 77921 35325 15981 85858 52261 62486 60546 95741 22231 52644 35359 8133 12936 7015 24244 77507 19072 82733 31180 75724 98461 69539 31906 
5032 91327 83485 44556 38773 67268 79830 48696 19997 44925 60913 88974 29328 80092 45849 46619 89707 21620 21020 22424 96232 11181 63496 65116...

result:

ok 

Test #69:

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

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:

73
82010 22705 20205 74446 75381 57709 76176 47072 62022 15775 4787 27086 25314 3761 30492 33118 49825 12058 9202 26275 54907 8128 68582 46139 29461 3385 75863 11268 23678 50248 88525 31915 21023 30655 86110 37236 64738 57726 4857 43863 92931 15037 79417 53619 25179 27419 32834 70236 44295 45974 682...

result:

ok 

Test #70:

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

input:

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

output:

4
2 1 5 4 
2 1 5 3 

result:

ok 

Test #71:

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

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:

105
73743 23990 7512 27839 57676 41727 26358 44833 2171 32737 16736 11487 90122 84186 57484 93062 73056 47709 46773 74011 34420 83670 81260 26713 54052 12215 16193 1947 34476 27159 52054 44292 16991 57167 44623 36886 12586 54734 54491 73644 27538 7987 32 54211 76880 32048 47412 10225 5497 83273 8347...

result:

ok 

Test #72:

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

input:

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

output:

3
3 5 6 
5 3 2 

result:

ok 

Test #73:

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

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
3 6 1 
7 5 3 

result:

ok 

Test #74:

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

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
7 8 6 5 
7 8 6 3 

result:

ok 

Test #75:

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

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:

3
8 9 5 
9 5 4 

result:

ok 

Test #76:

score: -100
Time Limit Exceeded

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:


result: