QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#532822#5088. Two ChoreographiesBongoCatEnjoyer#AC ✓205ms49456kbC++143.8kb2024-08-25 12:46:572024-08-25 12:46:58

Judging History

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

  • [2024-08-25 12:46:58]
  • 评测
  • 测评结果:AC
  • 用时:205ms
  • 内存:49456kb
  • [2024-08-25 12:46:57]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define forn(i, n) for (ll i = 0; i < n; ++i)
#define forr(i, s, n) for (ll i = s; i < n; ++i)
#define fori(i, s, n) for (ll i = s; i > n; --i)
#define fora(i, n) for (auto i: n)
#define vi vector<int>
#define vll vector<ll>
#define prints(n) cout << (n) << " "
#define println(n) cout << (n) << "\n"

const int MOD = 998244353;
// const int MOD = 1e9 + 7;
vector<vi> adj;

vi dep;
vi par;
vector<vi> spt;
vi vis;

vector<pair<int, int>> vp;
vector<vector<pair<int, int>>> cy;


void dfs(int u, int p, int d=1) {
    if (vis[u] < 0) {
        return;
    }
    if (vis[u]) {
        // cout << u << ' ' << p << endl;
        vp.emplace_back(u, p);
        return;
    }
    // cout << u + 1 << ' ' << p + 1 << ' ' << d << endl;
    dep[u] = d;
    par[u] = p;
    vis[u] = 1;
    for (int v: adj[u]) {
        if (v == p) continue;
        // cout << u + 1 <<' ' << v+1 << "   " << vis[v] << endl;
        if (vis[v] == 0) vis[v] = -d;
    }
    for (int v: adj[u]) {
        if (v == p) continue;
        if (vis[v] == -d) vis[v] = 0;
        else if (vis[v] < 0) continue;
        dfs(v, u, d + 1);
    }
}

int lca(int u, int v) {
    if (dep[u] < dep[v]) swap(u, v);
    int jarak = dep[u] - dep[v];
    forn(i, 25) {
        if (jarak & (1 << i)) u = spt[u][i];
    }
    for (int i = 24; i >= 0; i--) {
        if (spt[u][i] != spt[v][i]) {
            u = spt[u][i];
            v = spt[v][i];
        }
    }
    while (u != v) {
        u = par[u];
        v = par[v];
    }
    return u;
}

int jarak (int u, int v) {
    return dep[u] + dep[v] - 2 * dep[lca(u, v)];
}

void procSpt() {
    forn(b, 25) {
        forn(i, adj.size()) {
            if (b) spt[i][b] = spt[spt[i][b - 1]][b - 1];
            else spt[i][b] = par[i];
        }
    }
}

void proc() {
    forn(i, vp.size()) {
        if (vp[i].first > vp[i].second) swap(vp[i].first, vp[i].second);
    }
    sort(vp.begin(), vp.end());
    vp.erase(unique(vp.begin(), vp.end()), vp.end());

    forn(i, vp.size()) {
        int u = vp[i].first, v = vp[i].second;
        int j = jarak(u, v);
        cy[j].push_back({u, v});
    }
}

void printcycle(int u, int v) {
    int _lca = lca(u, v);
    stack<int> rev;
    while (u != _lca) {
        rev.push(u+1);
        u = par[u];
    }
    cout << v + 1<< ' ';
    while (v != _lca) {
        v = par[v];
        cout << v + 1 << ' ';
    }
    while (!rev.empty()) {
        cout << rev.top() << (rev.size() == 1 ? "" : " ");
        rev.pop();
    }
    cout << '\n';
}

void solve() {
    int n;
    cin >> n;
    adj.resize(n);
    dep = vi(n, 0);
    par = vi(n, 0);
    vis = vi(n, 0);
    cy = vector<vector<pair<int, int>>>(n+2, vector<pair<int, int>>());
    spt = vector<vi>(n, vi(25, 0));


    forn(i, 2*n - 3) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    forn(i, n) {
        if (adj[i].size() > 2) {
            dfs(i, i);
            // cout << "PPP" << i << '\n';
            break;
        }
    }

    // dfs(0, 0);
    forn(i, n) {
        if (vis[i]) continue;
        dfs(i, i);
    }
    procSpt();
    proc();

    for(int i = cy.size() - 1; i >= 2; i--) {
        if (cy[i].size() > 1) {
            cout << i + 1 << '\n';
            printcycle(cy[i][0].first, cy[i][0].second);
            printcycle(cy[i][1].first, cy[i][1].second);
            return;
        }
    }



    cout << -1 << '\n';
    
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

詳細信息

Test #1:

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

input:

4
1 2
1 3
1 4
2 3
2 4

output:

3
3 1 2
4 1 2

result:

ok 

Test #2:

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

input:

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

output:

3
3 1 2
5 1 2

result:

ok 

Test #3:

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

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

result:

ok 

Test #4:

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

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:

7
38 3 25 31 15 18 9
39 9 18 15 31 25 34

result:

ok 

Test #5:

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

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:

14
145 197 75 57 155 199 128 8 113 184 107 60 130 9
175 64 88 35 85 82 95 97 153 31 34 39 7 36

result:

ok 

Test #6:

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

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:

424
4963 7161 2819 2184 4856 2682 6758 6258 1195 7334 1112 5249 5538 5940 6803 4954 5493 341 7028 3457 6436 1016 2684 1743 219 1946 4059 3101 6075 2254 1307 6881 7035 5180 5507 3229 1673 6762 4639 2865 2729 3756 94 7506 6210 5448 6491 4891 2336 2929 444 55 5497 4515 2643 3876 3406 2954 6426 6011 326...

result:

ok 

Test #7:

score: 0
Accepted
time: 161ms
memory: 43424kb

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:

4886
76591 69699 12190 5413 160 9146 11711 8478 7515 64435 14188 26202 10761 72242 89297 29234 70302 9589 3874 9337 40710 942 50159 3314 22722 66524 22519 31269 7280 8465 20890 4104 5583 4756 21390 4328 348 33317 61723 36133 6618 5897 99874 23839 8706 4861 36121 22133 1268 59342 54704 17526 18986 79...

result:

ok 

Test #8:

score: 0
Accepted
time: 162ms
memory: 43336kb

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:

4942
70132 12481 20930 10015 33477 43114 7894 5272 13198 52318 4098 85417 78989 4455 48899 15139 61187 16874 37796 8400 28400 9933 1834 2172 94522 27932 18421 30286 7228 18125 1239 67531 8582 8369 9929 17784 13996 12763 49232 29098 10285 49587 13259 24302 35097 24024 11424 59657 7214 3359 38626 2402...

result:

ok 

Test #9:

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

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

result:

ok 

Test #10:

score: 0
Accepted
time: 67ms
memory: 42684kb

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:

17
47411 1 47396 47397 47398 47399 47400 47401 47402 47403 47404 47405 47406 47407 47408 47409 47410
100000 1 47396 47397 47398 47399 47400 47401 47402 47403 47404 47405 47406 47407 47408 47409 47410

result:

ok 

Test #11:

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

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:

4
4 1 2 3
8 1 2 3

result:

ok 

Test #12:

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

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

result:

ok 

Test #13:

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

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:

5
9 1 6 7 8
10 1 6 7 8

result:

ok 

Test #14:

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

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:

11
783 1 774 775 776 777 778 779 780 781 782
1000 1 774 775 776 777 778 779 780 781 782

result:

ok 

Test #15:

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

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:

21
9737 1 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736
9999 1 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736

result:

ok 

Test #16:

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

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:

15
931 1 918 919 920 921 922 923 924 925 926 927 928 929 930
6775 1 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774

result:

ok 

Test #17:

score: 0
Accepted
time: 66ms
memory: 40400kb

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:

17
75570 1 75555 75556 75557 75558 75559 75560 75561 75562 75563 75564 75565 75566 75567 75568 75569
94753 1 75555 75556 75557 75558 75559 75560 75561 75562 75563 75564 75565 75566 75567 75568 75569

result:

ok 

Test #18:

score: 0
Accepted
time: 58ms
memory: 42360kb

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:

18
95923 1 95907 95908 95909 95910 95911 95912 95913 95914 95915 95916 95917 95918 95919 95920 95921 95922
99999 1 95907 95908 95909 95910 95911 95912 95913 95914 95915 95916 95917 95918 95919 95920 95921 95922

result:

ok 

Test #19:

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

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

result:

ok 

Test #20:

score: 0
Accepted
time: 58ms
memory: 43072kb

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

result:

ok 

Test #21:

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

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

result:

ok 

Test #22:

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

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

result:

ok 

Test #23:

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

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

result:

ok 

Test #24:

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

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

result:

ok 

Test #25:

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

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

result:

ok 

Test #26:

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

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

result:

ok 

Test #27:

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

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

result:

ok 

Test #28:

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

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

result:

ok 

Test #29:

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

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

result:

ok 

Test #30:

score: 0
Accepted
time: 72ms
memory: 49284kb

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

result:

ok 

Test #31:

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

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

result:

ok 

Test #32:

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

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

result:

ok 

Test #33:

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

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

result:

ok 

Test #34:

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

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

result:

ok 

Test #35:

score: 0
Accepted
time: 8ms
memory: 7716kb

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

result:

ok 

Test #36:

score: 0
Accepted
time: 8ms
memory: 7896kb

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

result:

ok 

Test #37:

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

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

result:

ok 

Test #38:

score: 0
Accepted
time: 74ms
memory: 49456kb

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

result:

ok 

Test #39:

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

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:

5
4 5 6 7 3
8 1 5 6 7

result:

ok 

Test #40:

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

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:

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

result:

ok 

Test #41:

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

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:

330
998 997 458 459 460 461 668 667 666 665 418 401 402 34 33 32 31 66 67 68 69 70 38 368 531 932 514 515 552 543 644 226 299 888 889 890 281 528 920 921 273 274 506 505 504 464 575 574 168 167 646 811 812 277 278 279 231 230 238 237 695 871 872 873 715 389 522 523 612 611 848 22 689 688 49 50 722 5...

result:

ok 

Test #42:

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

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:

2856
6463 6462 3181 3182 5541 5540 5539 5538 5537 1868 9507 9508 9509 8114 8115 8116 2651 9089 4976 4975 6912 3761 3185 3487 3486 3485 2408 2409 2410 2411 2412 2413 6058 210 598 599 6933 8353 8354 9877 7991 7992 7993 7994 8907 8908 8909 6812 7481 7480 7479 1469 9676 1922 4447 5935 117 116 9833 9832 ...

result:

ok 

Test #43:

score: 0
Accepted
time: 11ms
memory: 7496kb

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:

2977
1291 1292 2631 2632 2633 2634 2635 1055 3060 3059 5621 8485 8486 8487 7716 7715 7028 7027 7026 4808 4904 4903 4902 9380 9379 2758 927 928 929 7694 7693 6941 6942 3687 3686 1181 1180 1179 1178 1177 1176 1175 1174 6163 6164 1943 8877 8878 2050 2049 2048 2984 5873 4581 4582 4445 4446 4447 5836 583...

result:

ok 

Test #44:

score: 0
Accepted
time: 169ms
memory: 45284kb

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:

29502
42678 88370 18375 18374 18373 18372 72030 72031 72032 72033 30760 30759 83040 83041 73627 73628 73629 73630 68307 52207 52208 52209 64606 36579 88860 52238 52239 61297 5787 58258 58259 8106 8105 86259 3738 3739 96648 36271 36272 36273 65803 65802 79301 12729 41037 32982 32981 8725 8726 46479 4...

result:

ok 

Test #45:

score: 0
Accepted
time: 185ms
memory: 43348kb

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:

28528
4574 4575 1008 68891 68890 78233 4475 42134 42135 42136 3078 57632 15566 15567 16189 16190 64883 64882 64881 33204 50683 50682 33475 74810 74811 16875 16876 16877 16878 16879 16880 16881 58022 58021 58020 58019 61420 61421 61422 72531 24453 85474 85475 85476 3779 3780 3781 42421 42420 27875 27...

result:

ok 

Test #46:

score: 0
Accepted
time: 188ms
memory: 45148kb

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:

29768
48283 83943 83944 83945 83946 38851 38850 38849 42028 42029 42030 42031 2481 2482 36096 49288 43064 43063 43062 43061 68958 89645 25205 231 230 229 228 227 226 12852 27190 27189 16773 16774 68104 68103 74940 74941 95277 95276 95275 4136 4135 84753 84752 31127 31128 31129 31130 41842 56233 7614...

result:

ok 

Test #47:

score: 0
Accepted
time: 201ms
memory: 45088kb

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:

29465
46434 90097 90096 90095 14746 96122 96121 96120 56814 36784 36783 36782 88047 35059 35058 35057 31822 31823 31824 31825 50713 50712 29095 90637 7726 7727 78587 78588 78589 78590 23459 3484 76328 48324 54043 80199 80198 80197 41403 41402 3802 32855 32856 96998 96999 18935 18934 2485 2484 28910 ...

result:

ok 

Test #48:

score: 0
Accepted
time: 187ms
memory: 44844kb

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:

29760
67064 67065 67066 67067 67068 26899 26900 26901 26902 26903 26357 26356 92201 92200 92199 92198 29537 93087 93088 93089 93090 73417 73416 73415 27832 27831 27830 79067 79066 42399 57661 81032 25208 5271 10503 10502 29327 96480 13337 38757 64002 72901 72902 72903 73819 73820 89799 89798 2969 29...

result:

ok 

Test #49:

score: 0
Accepted
time: 156ms
memory: 42468kb

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:

27684
53370 72261 93135 93136 93137 93138 42625 59308 34103 34102 59579 59578 59577 82311 82310 82309 82308 8700 8699 8698 8697 57214 57213 75823 59494 59495 83235 83234 83233 83232 16094 16095 16096 7653 7654 77875 77876 77877 77878 19176 94009 94008 94007 94006 31824 38284 38283 38282 24705 72713 ...

result:

ok 

Test #50:

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

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

result:

ok 

Test #51:

score: 0
Accepted
time: 190ms
memory: 44560kb

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:

29377
36177 36176 36175 36174 36173 53027 5740 77275 78260 80376 39859 53803 53804 10943 12552 32220 58448 58449 58450 58451 38310 29218 29217 29216 54954 54953 54952 54951 34876 49266 68841 68840 65908 65907 34707 78705 44096 44097 16310 16309 5945 5944 43003 43002 17519 17520 17521 17522 20184 201...

result:

ok 

Test #52:

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

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:

5
7 3 2 1 6
8 1 2 3 7

result:

ok 

Test #53:

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

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:

5
5 6 2 1 4
9 1 2 6 8

result:

ok 

Test #54:

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

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:

4
6 5 4 3
8 1 5 7

result:

ok 

Test #55:

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

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

result:

ok 

Test #56:

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

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:

6
7 8 9 2 1 4
7 8 9 2 1 6

result:

ok 

Test #57:

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

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:

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

result:

ok 

Test #58:

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

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

result:

ok 

Test #59:

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

input:

4
1 2
4 1
4 3
3 1
4 2

output:

3
4 1 2
4 1 3

result:

ok 

Test #60:

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

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:

5
9 1 3 6 5
10 6 3 1 8

result:

ok 

Test #61:

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

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:

255
344 241 222 737 819 446 633 72 47 710 736 151 720 709 109 336 767 765 298 702 280 91 25 397 945 425 958 347 388 440 701 494 185 190 351 370 820 738 795 525 955 946 470 980 909 652 544 5 870 259 540 428 250 264 913 581 891 204 605 902 705 696 760 308 477 570 900 591 283 212 503 356 502 623 743 30...

result:

ok 

Test #62:

score: 0
Accepted
time: 11ms
memory: 7248kb

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:

2384
9287 9140 9834 2139 1188 7638 3352 300 5876 8318 6451 2821 7061 9000 920 2403 2773 3381 7591 7769 5563 407 4595 7960 9710 6949 8392 9578 9459 1378 9052 1596 9824 49 7466 7780 5040 8167 3694 9943 6266 7180 106 8836 9510 5021 9924 9946 1425 9668 4931 3330 7605 1933 429 4600 9261 9458 6626 2710 23...

result:

ok 

Test #63:

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

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:

2368
3224 4469 3309 7849 9015 3327 6499 1601 4404 5502 9097 2003 4126 9995 175 9294 6640 4708 7366 9661 102 3485 4477 2469 5734 4542 4663 5319 4862 140 5049 3939 3696 246 543 9659 9054 708 1123 7400 1859 5655 17 2340 8426 9234 849 6118 9771 7418 7315 3575 9225 5068 551 3043 3029 1843 8555 6415 2906 ...

result:

ok 

Test #64:

score: 0
Accepted
time: 192ms
memory: 44964kb

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:

24097
42294 8038 85124 48980 75948 4867 55405 27786 70341 38359 47304 26528 89623 27994 19651 94708 61726 11138 57813 99481 73629 98976 44543 78092 38779 63448 40776 83008 72621 15028 13486 54514 44562 74989 18139 98494 2298 24563 68889 10552 2117 51240 9826 9072 99142 10350 39484 20747 29365 26045 ...

result:

ok 

Test #65:

score: 0
Accepted
time: 185ms
memory: 41212kb

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:

22542
89214 81237 8058 86959 74874 83089 30981 39613 539 41056 3763 57959 52107 87358 41035 78786 11596 6354 60578 22923 22126 83812 17566 4911 4266 61464 49084 83818 6446 15658 2222 56756 6183 74876 70066 77397 27723 80232 2942 6853 8489 13287 23942 10661 73139 3506 50253 12884 17222 54817 37031 74...

result:

ok 

Test #66:

score: 0
Accepted
time: 205ms
memory: 44844kb

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:

24277
55213 69134 7962 83206 25836 38157 32652 35268 69782 13120 13375 45209 11521 7524 89470 57782 95927 78691 27476 90022 27673 45995 2456 76004 45471 39506 48167 36027 54278 57195 20435 21258 91854 35270 73311 24240 40898 81757 75017 60038 46413 21921 49193 36343 88699 51232 25505 50706 3238 6140...

result:

ok 

Test #67:

score: 0
Accepted
time: 200ms
memory: 44520kb

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:

23972
96532 4766 47398 6197 16439 97230 67804 70501 92842 80036 11274 28042 69511 68526 66929 77016 61 56084 88831 1159 49672 40686 22556 93339 65667 72823 74318 1614 6482 93139 90623 4164 4963 63982 89919 22194 27014 25790 66315 53010 37460 86244 21508 5178 25024 6411 53342 96120 99642 70097 59285 ...

result:

ok 

Test #68:

score: 0
Accepted
time: 200ms
memory: 44780kb

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:

23935
38507 33976 41764 39324 7099 36167 38698 39959 45550 56378 31109 29054 32136 72098 4351 72660 84230 17997 90617 30503 12210 90957 81753 75654 69782 72713 35207 13103 6621 3873 11785 6727 96755 94183 4541 25706 65135 86381 8519 70874 56118 81803 29389 20035 42145 35472 38838 5736 11447 75366 39...

result:

ok 

Test #69:

score: 0
Accepted
time: 182ms
memory: 42952kb

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:

23216
90748 42488 41932 15101 56842 66435 42404 30235 29156 25047 5915 2899 59565 49420 14950 4206 23777 36067 6304 49362 31872 26829 44802 92436 84058 1569 25512 95582 70076 78478 6268 49142 78635 79836 56706 66392 43300 53872 48774 67636 88289 24775 61003 64830 57384 22168 33170 43088 59269 17746 ...

result:

ok 

Test #70:

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

input:

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

output:

3
3 1 2
5 1 3

result:

ok 

Test #71:

score: 0
Accepted
time: 193ms
memory: 42044kb

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:

22903
43985 65086 72865 35458 50112 22674 31670 87541 25823 8750 4331 41360 18501 41821 467 2633 42866 4912 12182 16890 9200 69377 92913 72555 26882 13720 15340 20371 6105 56215 85432 65900 16032 41135 1296 75300 91152 47822 18215 11565 32843 82462 47530 39807 72332 48485 15471 44318 51768 49462 455...

result:

ok 

Test #72:

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

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

result:

ok 

Test #73:

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

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

result:

ok 

Test #74:

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

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

result:

ok 

Test #75:

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

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 4 2 5
9 2 4 8

result:

ok 

Test #76:

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

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:

5
5 9 8 3 4
10 9 8 3 4

result:

ok 

Test #77:

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

input:

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

output:

4
6 3 2 4
6 3 2 5

result:

ok 

Test #78:

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

input:

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

output:

4
10 1 3 2
10 1 3 4

result:

ok