QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#304622#5088. Two Choreographieswarner1129AC ✓45ms20056kbC++204.7kb2024-01-13 22:00:102024-01-13 22:00:11

Judging History

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

  • [2024-01-13 22:00:11]
  • 评测
  • 测评结果:AC
  • 用时:45ms
  • 内存:20056kb
  • [2024-01-13 22:00:10]
  • 提交

answer

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

template<ranges::range T, class = enable_if_t<!is_convertible_v<T, string_view>>>
istream& operator>>(istream &s, T &&v) { for (auto &&x : v) s >> x; return s; }
template<ranges::range T, class = enable_if_t<!is_convertible_v<T, string_view>>>
ostream& operator<<(ostream &s, T &&v) { for (auto &&x : v) s << x << ' '; return s; }
 
#ifdef LOCAL
template<class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
#define debug(x...) dbg(#x, '=', x, '\n')
#else
#define debug(...) ((void)0)
#endif
 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
 
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using Pt = pair<i64, i64>;
 
template<class T> inline constexpr T inf = numeric_limits<T>::max() / 2;
constexpr int mod = 1e9 + 7, inv2 = (mod + 1) / 2;
constexpr double eps = 1e-9;
 
template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }

Pt operator+(Pt a, Pt b) { return {a.ff + b.ff, a.ss + b.ss}; }
Pt operator-(Pt a, Pt b) { return {a.ff - b.ff, a.ss - b.ss}; }
i64 operator^(Pt a, Pt b) { return a.ff * b.ss - a.ss * b.ff; }
i64 operator*(Pt a, Pt b) { return a.ff * b.ff + a.ss * b.ss; }
i64 cro(Pt a, Pt b, Pt c) { return (b - a) ^ (c - a); }
i64 norm(Pt a) { return a * a; }

struct DSU {
    vector<int> f;
    DSU(int n) : f(n, -1) {}
    int Find(int x) { return f[x] < 0 ? x : f[x] = Find(f[x]); }
    bool Union(int x, int y) {
        x = Find(x);
        y = Find(y);
        if (x == y) return false;
        f[x] = y;
        return true;
    }
};

void solve() {
    int n;
    cin >> n;

    vector<pair<int, int>> edg(n * 2 - 3);
    for (auto &[u, v] : edg) {
        cin >> u >> v;
        u--, v--;
    }

    mt19937 rng(1112);
    shuffle(all(edg), rng);

    vector G(n, vector<int>{});
    DSU dsu(n);
    vector<int> res;
    for (int i = 0; i < n * 2 - 3; i++) {
        auto [u, v] = edg[i];
        if (!dsu.Union(u, v)) {
            res.push_back(i);
        } else {
            G[u].push_back(v);
            G[v].push_back(u);
        }
    }

    vector<int> seq, dep(n), pa(n, -1), in(n);
    vector<bool> vis(n);
    auto dfs = [&](auto self, int u, int f) -> void {
        vis[u] = 1;
        if (f != -1) dep[u] = dep[f] + 1;
        in[u] = seq.size();
        seq.push_back(u);
        
        pa[u] = f;
        for (int v : G[u]) if (v != f) {
            self(self, v, u);
        }
    };
    
    dfs(dfs, rng() % n, -1);
    for (int i = 0; i < n; i++)
        if (!vis[i]) {
            dfs(dfs, i, -1);
        }

    const int lgN = __lg(n);
    vector st(lgN + 1, vector<int>(n));
    st[0] = seq;
    auto cmp = [&](int x, int y) {
        return dep[x] < dep[y] ? x : y;
    };
    for (int i = 0; i < lgN; i++)
        for (int j = 0; j + (1 << i) < n; j++)
            st[i + 1][j] = cmp(st[i][j], st[i][j + (1 << i)]);

    auto lca = [&](int x, int y) {
        if (x == y) return x;
        if ((x = in[x] + 1) > (y = in[y] + 1))
            swap(x, y);
        int h = __lg(y - x);
        return pa[cmp(st[h][x], st[h][y - (1 << h)])];
    };
    
    auto dist = [&](int x, int y) {
        return dep[x] + dep[y] - 2 * dep[lca(x, y)];
    };

    pair<int, int> cyc{-1, -1};

    vector<int> deg(n);
    map<int, int> len;
    for (int i : res) {
        auto [u, v] = edg[i];
        int w = dist(u, v);
        if (len[w]) {
            cyc = {i, len[w]};
            break;
        } else {
            len[w] = i;
        }
        deg[u]++, deg[v]++;
    }

    auto getcyc = [&](int a, int b) -> vector<int> {
        int l = lca(a, b);
        vector<int> A, B;
        while (a != l) {
            A.push_back(a + 1);
            a = pa[a];
        }
        while (b != l) {
            B.push_back(b + 1);
            b = pa[b];
        }
        A.push_back(l + 1);
        A.insert(A.end(), rall(B));
        return A;
    };

    if (cyc.ff != -1) {
        auto [a, b] = cyc;
        auto A = getcyc(edg[a].ff, edg[a].ss);
        auto B = getcyc(edg[b].ff, edg[b].ss);
        cout << A.size() << '\n';
        cout << A << '\n' << B << '\n';
    } else {
        if (deg[seq[0]] < deg[seq[n - 1]]) {
            reverse(all(seq));
        }
        cout << 3 << '\n';
        cout << seq[0] + 1 << ' ' << seq[1] + 1 << ' ' << seq[2] + 1 << '\n';
        cout << seq[0] + 1 << ' ' << seq[n - 2] + 1 << ' ' << seq[n - 1] + 1 << '\n';
    }
}
 
signed main() {
    cin.tie(0)->sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 2
1 3
1 4
2 3
2 4

output:

3
2 1 4 
1 2 3 

result:

ok 

Test #2:

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

input:

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

output:

3
1 4 3 
1 5 2 

result:

ok 

Test #3:

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

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

result:

ok 

Test #4:

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

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
5 7 11 
25 31 28 

result:

ok 

Test #5:

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

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:

5
113 110 90 134 172 
70 113 110 90 134 

result:

ok 

Test #6:

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

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:

26
3204 7438 7940 1754 4482 3 5268 1515 1787 7654 57 4876 5975 118 1176 5702 7205 3378 5561 1738 3126 6993 1719 59 6361 3247 
6137 3319 4439 4587 3868 890 2480 381 2039 7662 6456 5891 3655 354 7928 1544 5645 4934 5235 6984 1979 3698 6405 844 7617 2639 

result:

ok 

Test #7:

score: 0
Accepted
time: 38ms
memory: 19764kb

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:

3
3978 36895 12863 
3692 71957 32428 

result:

ok 

Test #8:

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

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:

13
96197 82790 79574 95472 13478 19413 68359 96284 43352 87595 18472 92269 85786 
74130 2014 71197 50837 47445 43998 8010 75896 31904 75497 32376 80268 41922 

result:

ok 

Test #9:

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

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:

3
5 7 6 
7 6 1 

result:

ok 

Test #10:

score: 0
Accepted
time: 29ms
memory: 19996kb

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 93727 1 78606 
1 93727 100000 44277 

result:

ok 

Test #11:

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

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

result:

ok 

Test #12:

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

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

result:

ok 

Test #13:

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

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

result:

ok 

Test #14:

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

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:

5
1 109 1000 415 414 
984 1 109 1000 985 

result:

ok 

Test #15:

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

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 4719 1 4494 
9999 4719 1 6696 

result:

ok 

Test #16:

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

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 4469 1 572 
10000 4469 1 3420 

result:

ok 

Test #17:

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

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 46154 1 43432 
1 46154 94753 149 

result:

ok 

Test #18:

score: 0
Accepted
time: 31ms
memory: 20056kb

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 88516 1 87486 
1 88516 99999 42987 

result:

ok 

Test #19:

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

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

result:

ok 

Test #20:

score: 0
Accepted
time: 38ms
memory: 20024kb

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 86653 86652 
1 73322 73321 

result:

ok 

Test #21:

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

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

result:

ok 

Test #22:

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

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

result:

ok 

Test #23:

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

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

result:

ok 

Test #24:

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

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
709 1 710 
1 444 443 

result:

ok 

Test #25:

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

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 5798 5799 
1 1156 1157 

result:

ok 

Test #26:

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

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 8546 8545 
1 1155 1156 

result:

ok 

Test #27:

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

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
87847 1 87848 
1 58679 58678 

result:

ok 

Test #28:

score: 0
Accepted
time: 41ms
memory: 20056kb

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
81749 1 81750 
1 95018 95017 

result:

ok 

Test #29:

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

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

result:

ok 

Test #30:

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

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
94712 100000 94713 
100000 45749 45748 

result:

ok 

Test #31:

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

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

result:

ok 

Test #32:

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

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

result:

ok 

Test #33:

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

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

result:

ok 

Test #34:

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

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 75 76 
47 1000 48 

result:

ok 

Test #35:

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

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 1357 1358 
9999 8705 8706 

result:

ok 

Test #36:

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

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 2460 2461 
2420 10000 2421 

result:

ok 

Test #37:

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

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 23083 23082 
92892 80496 80497 

result:

ok 

Test #38:

score: 0
Accepted
time: 38ms
memory: 19960kb

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 52444 52445 
99999 6493 6494 

result:

ok 

Test #39:

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

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

result:

ok 

Test #40:

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

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

result:

ok 

Test #41:

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

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:

36
897 935 939 940 359 360 474 473 472 469 328 956 955 461 635 38 37 36 557 558 58 59 607 606 841 881 880 879 15 960 959 958 78 429 430 896 
164 431 432 748 747 451 452 453 454 474 473 472 469 328 956 955 461 635 38 37 36 557 558 58 59 607 606 841 881 880 879 15 960 877 731 732 

result:

ok 

Test #42:

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

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:

8
807 9442 9443 1112 1113 8743 8834 808 
2733 2732 9010 9011 1102 5727 5726 1295 

result:

ok 

Test #43:

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

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:

62
3719 3829 3830 3831 3832 1901 193 192 3366 8406 1599 6484 6483 8099 8098 7577 4913 6512 6511 8397 8061 8062 8871 3559 965 966 3751 3750 9817 9818 8576 8575 8574 3240 3239 4205 455 454 6341 850 2225 7410 7409 790 8071 8070 1740 1741 8861 1488 1489 4397 7144 7145 8237 8236 8858 8857 6270 7123 7124 ...

result:

ok 

Test #44:

score: 0
Accepted
time: 38ms
memory: 19800kb

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:

262
62849 92146 98294 95540 8922 19517 19516 19515 93908 93907 30682 30681 2211 81635 75915 75914 75913 45153 38221 38220 36860 36859 43434 43433 43432 49573 58562 58563 16307 16306 15796 15795 61509 83209 55258 55259 55260 7688 86807 54334 54335 54336 74247 90418 90417 16426 16427 16428 76183 76184...

result:

ok 

Test #45:

score: 0
Accepted
time: 41ms
memory: 19288kb

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:

108
71527 71526 76976 76975 85536 85535 85534 19123 19122 19121 42954 6358 6357 6356 36070 36071 34817 23021 21865 40501 70115 54320 77673 77672 17114 25216 33573 33572 92858 92857 59122 71025 71024 71023 11745 11746 46963 20404 51092 79993 72856 72857 10519 10518 52325 52324 43586 31536 55717 55716...

result:

ok 

Test #46:

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

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:

51
58369 32268 88992 88991 83045 9914 9915 76237 76236 76235 32761 8222 8223 84934 84933 5766 5767 5768 1166 1167 76003 65582 39362 39363 21908 21907 18784 96473 72181 24407 29602 93782 44730 24513 86619 86618 52425 23541 36425 22355 64616 64617 18078 18079 11549 84512 47709 15066 76414 76413 58368 ...

result:

ok 

Test #47:

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

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:

39
85361 79824 13218 71606 86662 84175 84176 36250 5989 5990 5991 77928 26883 80230 36318 4286 31131 31130 31129 44421 17287 28365 28364 28363 60455 60454 32383 7155 1880 4563 4562 4561 57831 73881 73882 80359 80358 98044 85362 
37288 21007 69849 69850 70271 91708 91709 35018 32097 32098 83103 74533...

result:

ok 

Test #48:

score: 0
Accepted
time: 38ms
memory: 19804kb

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:

141
2964 80488 31805 31804 38486 64189 64190 44345 44346 7268 91757 91758 34743 34742 84112 46696 69685 69684 69683 71200 10835 19179 30434 82520 82519 79228 37764 37765 43599 53754 577 53823 65635 6835 58699 91755 44666 32923 32924 32925 26654 50414 50415 50416 24684 24683 24682 45754 45755 45756 6...

result:

ok 

Test #49:

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

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:

134
38929 18078 81811 81810 77420 50124 50125 50126 69108 69107 74781 74782 74783 74784 74785 83869 83870 63018 7 68115 68114 47498 47499 20170 20171 20172 42323 15325 49103 49104 21319 74334 73979 53461 53462 53463 53464 93120 19588 19589 49666 49665 61171 63585 63584 15808 73616 19837 65180 65181 ...

result:

ok 

Test #50:

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

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:

3
6 7 2 
6 7 5 

result:

ok 

Test #51:

score: 0
Accepted
time: 37ms
memory: 19644kb

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:

106
83896 27219 27220 27221 52517 52516 52515 12690 59142 41994 57001 77272 22639 22640 22641 1603 67019 81403 55595 8901 42641 86586 86587 28185 8847 47976 79016 79017 79018 74359 74358 74357 96468 98568 69334 92685 17987 88053 4573 4574 79584 85325 76164 42818 42819 42820 48667 26905 24312 24313 2...

result:

ok 

Test #52:

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

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

result:

ok 

Test #53:

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

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:

4
9 6 7 8 
2 3 4 1 

result:

ok 

Test #54:

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

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

result:

ok 

Test #55:

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

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:

4
7 8 1 2 
6 5 8 7 

result:

ok 

Test #56:

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

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

result:

ok 

Test #57:

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

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

result:

ok 

Test #58:

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

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:

6
4 6 7 9 1 5 
2 4 6 7 9 1 

result:

ok 

Test #59:

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

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

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:

4
8 3 4 10 
6 10 4 3 

result:

ok 

Test #61:

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

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:

13
264 237 965 396 895 903 309 15 974 618 77 374 250 
117 517 921 976 643 243 638 4 554 819 236 22 646 

result:

ok 

Test #62:

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

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:

22
6068 6002 8579 7512 9399 6588 9274 736 5913 6101 4301 4960 6048 5246 5163 8090 735 8989 399 6603 1552 8062 
9986 163 5704 3462 6531 7045 4465 4488 497 8052 4581 5506 644 8213 186 8966 9256 863 5620 2228 1831 9447 

result:

ok 

Test #63:

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

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:

64
8701 9852 7307 5620 9162 899 5127 733 2689 9624 7536 8089 5964 5631 9584 2796 4737 1471 3351 3128 6463 571 5507 1853 2051 1318 2058 3243 3079 7122 8218 3706 3373 5744 2990 3976 6585 278 1986 1166 1778 5922 9046 2186 9796 4201 7631 353 4793 7129 9431 5860 1434 7480 7343 7426 4976 6405 5951 5933 55...

result:

ok 

Test #64:

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

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:

44
56478 41425 37520 43901 43781 46832 60544 92508 16836 97640 85910 32412 64881 84525 80331 61969 6936 57057 78299 48115 76131 30342 46640 60789 93541 88866 27732 28397 82825 53044 3172 15259 34458 63031 32885 95853 64135 95407 69283 79834 25066 83341 38512 35959 
82601 84045 21188 32919 43926 2880...

result:

ok 

Test #65:

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

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:

141
26049 21625 14762 31440 36742 18120 11775 56941 77909 77749 20941 39418 20767 14587 47465 20975 48101 90170 29071 21088 49456 83870 33974 55721 15256 72980 80512 46486 12197 63750 30517 23431 28600 21237 70479 45349 72419 76403 40921 83044 28328 4944 74554 54177 59812 34010 83797 28486 84252 690...

result:

ok 

Test #66:

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

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:

40
34158 45403 78515 6433 58526 8858 9810 7825 26607 29386 59568 25637 54052 11046 86233 95362 75638 22310 56061 53777 17036 55797 10416 87795 90869 67686 41701 66887 77148 68954 81504 70116 31192 17843 19126 79824 82847 82613 44766 29659 
839 33067 16697 18643 83222 2068 72988 71167 47510 35834 660...

result:

ok 

Test #67:

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

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:

90
35680 72708 70256 21304 79912 13316 6236 67316 33423 82694 12504 86126 98347 92642 12231 45922 98280 25770 21419 99423 57368 1114 42084 10280 90024 76220 91700 92264 17739 51839 33375 19396 83243 47143 71252 84302 96021 56222 62989 78101 5524 41452 18618 28842 99959 87573 3846 25302 27745 57983 7...

result:

ok 

Test #68:

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

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:

88
22719 52376 99908 41878 62183 45252 32479 87525 48628 45804 50490 66073 41899 57997 62123 91014 62581 52421 63603 79597 53962 97674 98238 47353 82589 72609 7711 37563 60678 9307 97511 91470 59988 45645 65551 1574 73453 67061 28703 62261 17691 83811 15649 86620 33821 76261 41053 55315 84269 44361 ...

result:

ok 

Test #69:

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

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:

98
72361 20093 12895 6916 21739 21005 84115 25257 7460 52807 23048 34218 32418 32265 15018 41416 89939 31822 93126 86081 20702 58599 11637 75412 14542 64254 39578 78104 41614 51646 74775 89537 68479 85781 13649 27349 80156 48173 14774 80354 41465 23891 78702 88024 58126 37146 59870 89613 79339 75560...

result:

ok 

Test #70:

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

input:

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

output:

4
2 1 5 3 
2 1 5 4 

result:

ok 

Test #71:

score: 0
Accepted
time: 41ms
memory: 18756kb

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:

113
1629 81725 32665 82460 55312 53401 83836 37937 28504 10389 21045 15425 49142 56544 27170 30319 51688 89897 77517 67852 72499 8159 79472 6875 18002 25315 92572 32749 49818 41683 10589 8392 59708 57853 46609 35340 38116 8475 39944 29955 81727 29476 66346 25172 68070 78039 86100 23588 55626 78004 5...

result:

ok 

Test #72:

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

input:

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

output:

3
1 2 3 
5 1 2 

result:

ok 

Test #73:

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

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

result:

ok 

Test #74:

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

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

result:

ok 

Test #75:

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

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

result:

ok 

Test #76:

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

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

result:

ok 

Test #77:

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

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:

5
6 4 2 3 5 
5 3 2 4 7 

result:

ok 

Test #78:

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

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

result:

ok