QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#629256#4635. Graph Operationlwm7708AC ✓77ms5660kbC++178.6kb2024-10-11 09:56:272024-10-11 09:56:27

Judging History

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

  • [2024-10-11 09:56:27]
  • 评测
  • 测评结果:AC
  • 用时:77ms
  • 内存:5660kb
  • [2024-10-11 09:56:27]
  • 提交

answer

#include <algorithm>
#include <array>
#include <cstdint>
#include <ios>
#include <iostream>
#include <vector>

class bitset {

private:

    using blk_t = std::uint64_t;

    std::int32_t sz;
    std::int32_t blks;
    blk_t mask;

public:

    class reference {

    private:

        blk_t& blk;
        blk_t mask;

    public:

        explicit reference(blk_t& blk, std::int32_t bit) : blk(blk), mask(blk_t(1) << bit) {}

        operator bool() const {

            return (blk & mask) != 0;

        }

        void operator=(bool x) {

            if (!x) {
                blk &= ~mask;
            } else {
                blk |= mask;
            }

        }

    };

    std::vector<blk_t> data;

    explicit bitset() : bitset(0) {}

    explicit bitset(
        std::int32_t sz
    ) : sz(sz), blks((sz + 63) / 64), mask((sz % 64 ? blk_t(1) << (sz % 64) : 0) - 1), data(blks) {}

    reference operator[](std::int32_t pos) {

        return reference(data[pos / 64], pos % 64);

    }

    bool operator[](std::int32_t pos) const {

        return (data[pos / 64] >> (pos % 64) & 1) == 1;

    }

    bitset operator~() const {

        bitset res = *this;

        res.flip();

        return res;

    }

    void operator&=(const bitset& other) {

        for (std::int32_t i = 0; i < blks; ++i) {
            data[i] &= other.data[i];
        }

    }

    void operator|=(const bitset& other) {

        for (std::int32_t i = 0; i < blks; ++i) {
            data[i] |= other.data[i];
        }

    }

    void operator^=(const bitset& other) {

        for (std::int32_t i = 0; i < blks; ++i) {
            data[i] ^= other.data[i];
        }

    }

    void operator<<=(std::int32_t pos) {

        if (pos >= sz) {
            reset();
            return;
        }

        const std::int32_t bits = pos % 64;
        const std::int32_t shft = pos / 64;

        for (std::int32_t i = blks - 1; i >= shft; --i) {
            data[i] = data[i - shft] << bits;
            if (bits && i > shft) {
                data[i] |= data[i - shft - 1] >> (64 - bits);
            }
        }

        std::fill_n(std::begin(data), shft, 0);

    }

    void operator>>=(std::int32_t pos) {

        if (pos >= sz) {
            reset();
            return;
        }

        data[blks - 1] &= mask;

        const std::int32_t bits = pos % 64;
        const std::int32_t shft = pos / 64;

        for (std::int32_t i = 0; i < blks - shft; ++i) {
            data[i] = data[i + shft] >> bits;
            if (bits && i < blks - shft - 1) {
                data[i] |= data[i + shft + 1] << (64 - bits);
            }
        }

        std::fill(std::end(data) - shft, std::end(data), 0);

    }

    bool all() const {

        for (std::int32_t i = 0; i < blks - 1; ++i) {
            if (~data[i]) {
                return false;
            }
        }

        return (data[blks - 1] & mask) == mask;

    }

    bool any() const {

        for (std::int32_t i = 0; i < blks - 1; ++i) {
            if (data[i]) {
                return true;
            }
        }

        return (data[blks - 1] & mask) != 0;

    }

    std::int32_t count() const {

        std::int32_t bits = __builtin_popcountll(data[blks - 1] & mask);

        for (std::int32_t i = 0; i < blks - 1; ++i) {
            bits += __builtin_popcountll(data[i]);
        }

        return bits;

    }

    void flip() {

        for (auto& x : data) {
            x ^= ~blk_t();
        }

    }

    bool none() const {

        return !any();

    }

    void reset() {

        std::fill_n(std::begin(data), blks, 0);

    }

    void set() {

        std::fill_n(std::begin(data), blks, ~blk_t());

    }

    std::int32_t size() const {

        return sz;

    }

    friend bool operator==(const bitset& lhs, const bitset& rhs) {

        if (lhs.sz != rhs.sz) {
            return false;
        }

        const std::int32_t len = lhs.blks;

        if (len == 0) {
            return true;
        }

        const std::vector<blk_t>& data_l = lhs.data;
        const std::vector<blk_t>& data_r = rhs.data;

        return std::equal(
            std::begin(data_l), std::begin(data_l) + len - 1, std::begin(data_r)
        ) && ((data_l[len - 1] ^ data_r[len - 1]) & lhs.mask) == 0;

    }

    friend bool operator!=(const bitset& lhs, const bitset& rhs) {

        return !(lhs == rhs);

    }

    friend bitset operator&(bitset lhs, const bitset& rhs) {

        lhs &= rhs;

        return lhs;

    }

    friend bitset operator|(bitset lhs, const bitset& rhs) {

        lhs |= rhs;

        return lhs;

    }

    friend bitset operator^(bitset lhs, const bitset& rhs) {

        lhs ^= rhs;

        return lhs;

    }

    friend bitset operator<<(bitset lhs, std::int32_t pos) {

        lhs <<= pos;

        return lhs;

    }

    friend bitset operator>>(bitset lhs, std::int32_t pos) {

        lhs >>= pos;

        return lhs;

    }

};

void solve() {

    using op = std::array<std::int32_t, 4>;

    std::int32_t m;
    std::int32_t n;

    std::cin >> n >> m;

    std::vector g_adj(n, bitset(n));

    for (std::int32_t i = 0; i < m; ++i) {
        std::int32_t u;
        std::int32_t v;
        std::cin >> u >> v;
        --u;
        --v;
        g_adj[u][v] = true;
        g_adj[v][u] = true;
    }

    std::vector h_adj(n, bitset(n));

    for (std::int32_t i = 0; i < m; ++i) {
        std::int32_t u;
        std::int32_t v;
        std::cin >> u >> v;
        --u;
        --v;
        h_adj[u][v] = true;
        h_adj[v][u] = true;
    }

    for (std::int32_t i = 0; i < n; ++i) {
        if (g_adj[i].count() != h_adj[i].count()) {
            std::cout << -1 << '\n';
            return;
        }
    }

    std::vector<op> g_ops;
    std::vector<op> h_ops;

    for (std::int32_t i = 0; i < n; ++i) {
        std::vector<std::int32_t> nodes_1;
        std::vector<std::int32_t> nodes_2;
        nodes_1.reserve(n / 2);
        nodes_2.reserve(n / 2);
        for (std::int32_t j = 0; j < n; ++j) {
            if (g_adj[i][j] && !h_adj[i][j]) {
                nodes_1.push_back(j);
            } else if (!g_adj[i][j] && h_adj[i][j]) {
                nodes_2.push_back(j);
            }
        }
        while (!std::empty(nodes_1)) {
            const auto apply = [](std::vector<bitset>& adj, const op& c_op) -> void {
                adj[c_op[0]][c_op[1]] = false;
                adj[c_op[1]][c_op[0]] = false;
                adj[c_op[2]][c_op[3]] = false;
                adj[c_op[3]][c_op[2]] = false;
                adj[c_op[0]][c_op[2]] = true;
                adj[c_op[2]][c_op[0]] = true;
                adj[c_op[1]][c_op[3]] = true;
                adj[c_op[3]][c_op[1]] = true;
            };
            const std::int32_t node_1 = nodes_1.back();
            const std::int32_t node_2 = nodes_2.back();
            bitset st = (~g_adj[node_1] & g_adj[node_2]) >> (i + 1) << (i + 1);
            st[node_1] = false;
            if (st.count()) {
                std::int32_t node = 0;
                while (st.data[node / 64] == 0) {
                    node += 64;
                }
                while (!st[node]) {
                    ++node;
                }
                g_ops.push_back(op({i, node_1, node_2, node}));
                apply(g_adj, g_ops.back());
            } else {
                st = (h_adj[node_1] & ~h_adj[node_2]) >> (i + 1) << (i + 1);
                st[node_2] = false;
                std::int32_t node = 0;
                while (st.data[node / 64] == 0) {
                    node += 64;
                }
                while (!st[node]) {
                    ++node;
                }
                h_ops.push_back(op({i, node_2, node_1, node}));
                apply(h_adj, h_ops.back());
            }
            nodes_1.pop_back();
            nodes_2.pop_back();
        }
    }

    std::cout << std::size(g_ops) + std::size(h_ops) << '\n';

    for (const auto& [a, b, c, d] : g_ops) {
        std::cout << a + 1 << ' ' << b + 1 << ' ' << c + 1 << ' ' << d + 1 << '\n';
    }

    std::reverse(std::begin(h_ops), std::end(h_ops));

    for (const auto& [a, b, c, d] : h_ops) {
        std::cout << a + 1 << ' ' << c + 1 << ' ' << b + 1 << ' ' << d + 1 << '\n';
    }

}

int main() {

    std::cin.tie(nullptr);

    std::ios_base::sync_with_stdio(false);

    solve();

    return 0;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 2
1 2
3 4
1 3
2 4

output:

1
1 2 3 4

result:

ok n=4

Test #2:

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

input:

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

output:

2
1 2 3 4
3 5 4 6

result:

ok n=6

Test #3:

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

input:

4 0

output:

0

result:

ok n=4

Test #4:

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

input:

10 0

output:

0

result:

ok n=10

Test #5:

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

input:

100 0

output:

0

result:

ok n=100

Test #6:

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

input:

1000 0

output:

0

result:

ok n=1000

Test #7:

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

input:

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

output:

0

result:

ok n=4

Test #8:

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

input:

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

output:

0

result:

ok n=10

Test #9:

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

input:

100 4950
15 37
36 56
57 64
66 63
35 70
8 65
25 36
1 27
6 74
79 22
35 34
79 70
53 74
41 63
7 40
41 22
99 93
96 70
35 30
20 67
48 65
100 21
8 4
75 87
80 10
82 38
7 10
85 77
42 77
28 64
73 60
20 74
73 86
24 31
73 44
97 93
8 74
48 19
63 42
41 57
25 79
13 19
96 39
59 44
81 20
66 2
8 37
34 23
88 27
12 14
...

output:

0

result:

ok n=100

Test #10:

score: 0
Accepted
time: 68ms
memory: 4200kb

input:

1000 499500
90 844
735 814
874 452
191 64
745 192
489 653
998 227
104 125
296 644
285 190
831 763
70 776
981 126
213 964
306 137
199 965
849 5
717 70
329 305
196 836
909 527
222 367
323 554
384 900
496 797
620 860
18 823
929 135
589 207
947 354
461 271
22 914
456 403
263 362
908 870
30 384
995 996
3...

output:

0

result:

ok n=1000

Test #11:

score: 0
Accepted
time: 64ms
memory: 4212kb

input:

1000 499500
561 780
496 694
698 721
598 412
55 527
799 952
790 473
980 139
375 308
605 850
670 77
77 908
958 436
379 504
293 452
735 666
223 901
944 455
554 123
644 817
723 68
157 867
527 755
380 937
904 851
614 666
299 131
369 83
61 651
820 239
432 583
588 869
500 542
502 996
305 43
601 882
277 337...

output:

0

result:

ok n=1000

Test #12:

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

input:

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

output:

0

result:

ok n=4

Test #13:

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

input:

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

output:

0

result:

ok n=4

Test #14:

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

input:

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

output:

-1

result:

ok n=10

Test #15:

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

input:

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

output:

-1

result:

ok n=10

Test #16:

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

input:

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

output:

-1

result:

ok n=10

Test #17:

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

input:

100 149
97 53
14 62
97 60
14 58
85 69
14 63
97 99
14 71
97 88
85 47
14 61
14 43
97 44
97 17
14 39
85 17
20 99
97 73
85 31
85 67
85 12
14 24
14 69
14 96
97 76
97 95
97 11
85 79
85 19
85 70
85 6
14 56
14 12
85 98
85 53
85 76
85 26
20 37
97 35
97 70
20 96
97 82
97 34
85 94
14 46
97 54
97 43
97 4
85 2
8...

output:

-1

result:

ok n=100

Test #18:

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

input:

100 4631
2 12
66 70
81 62
5 66
94 2
92 64
62 96
58 39
34 3
21 96
52 15
23 67
62 29
38 18
72 56
67 50
81 70
38 42
81 68
99 22
61 42
30 71
32 93
46 95
27 72
97 37
27 2
46 73
65 2
94 22
33 11
64 73
44 5
48 13
65 16
24 44
61 15
34 71
40 1
60 87
100 66
84 33
81 7
14 69
57 83
63 79
23 96
34 15
72 41
47 12...

output:

-1

result:

ok n=100

Test #19:

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

input:

1000 261943
229 141
480 681
189 131
575 202
700 642
405 254
845 739
920 506
838 6
366 32
886 326
124 749
375 702
426 316
843 800
736 845
752 171
744 236
169 313
612 804
675 808
230 804
454 695
617 445
606 481
766 254
140 421
483 155
775 115
617 583
710 417
936 649
329 53
526 979
833 382
464 327
475 ...

output:

-1

result:

ok n=1000

Test #20:

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

input:

1000 48821
306 916
554 937
602 467
778 306
291 993
446 28
561 538
566 718
833 139
857 553
738 128
153 811
350 290
458 146
211 897
158 828
925 574
291 91
530 933
833 387
773 926
554 776
900 41
158 186
877 717
975 113
360 451
375 101
980 364
96 203
492 953
29 280
469 540
153 604
44 911
601 229
469 858...

output:

-1

result:

ok n=1000

Test #21:

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

input:

4 1
4 1
4 1

output:

0

result:

ok n=4

Test #22:

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

input:

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

output:

0

result:

ok n=6

Test #23:

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

input:

6 1
3 1
1 2

output:

-1

result:

ok n=6

Test #24:

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

input:

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

output:

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

result:

ok n=10

Test #25:

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

input:

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

output:

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

result:

ok n=10

Test #26:

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

input:

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

output:

-1

result:

ok n=10

Test #27:

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

input:

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

output:

138
1 34 44 2
1 8 26 3
2 18 35 26
2 11 28 15
2 10 26 4
3 28 44 5
3 15 35 10
3 11 26 9
3 8 6 12
4 15 35 19
4 8 26 6
5 37 45 11
5 34 15 6
5 28 11 6
5 20 8 6
6 48 47 8
6 43 44 10
6 38 39 8
6 34 36 7
6 33 29 10
6 32 26 11
6 31 23 18
6 28 15 11
6 20 11 8
6 18 10 9
6 16 8 34
6 14 7 11
7 28 45 14
7 26 11 9...

result:

ok n=50

Test #28:

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

input:

50 409
50 22
17 47
45 41
30 9
12 29
15 13
6 14
6 34
6 15
45 25
7 11
17 20
17 23
35 2
24 8
30 22
35 18
31 44
39 38
31 23
37 23
21 10
21 14
35 1
30 17
35 46
11 10
17 39
21 32
1 18
12 5
49 14
46 41
37 4
7 9
1 46
12 9
7 8
35 23
17 1
37 35
49 47
37 48
46 13
36 10
24 17
46 23
15 29
7 1
11 16
31 4
43 25
31...

output:

-1

result:

ok n=50

Test #29:

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

input:

50 869
45 28
16 42
1 34
34 23
39 19
17 48
8 50
2 21
50 4
36 22
46 27
3 27
11 7
24 13
19 33
20 12
37 16
14 28
3 35
3 41
25 34
39 34
15 49
45 34
5 16
19 42
27 28
47 49
39 49
24 49
5 48
27 49
13 32
25 27
3 46
19 26
47 46
20 41
45 16
13 46
8 17
7 32
20 1
11 2
43 28
2 33
4 2
34 19
28 7
15 41
50 16
20 35
...

output:

175
1 24 38 3
1 20 29 2
1 12 18 9
2 47 31 3
2 20 18 3
3 44 38 8
3 40 31 4
3 24 25 4
3 20 18 4
3 12 10 6
3 9 6 5
4 40 38 12
4 20 31 9
4 13 25 5
4 12 18 13
4 9 10 8
5 47 44 8
5 29 38 28
5 24 36 8
5 18 25 7
5 10 20 6
5 8 6 10
6 47 45 7
6 46 44 10
6 43 42 8
6 32 41 8
6 29 39 8
6 17 20 9
6 9 13 10
6 8 10...

result:

ok n=50

Test #30:

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

input:

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

output:

-1

result:

ok n=50

Test #31:

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

input:

100 3627
14 28
100 63
90 38
28 96
64 4
65 85
46 72
41 44
81 87
27 91
66 5
33 22
21 87
58 20
23 95
93 56
46 62
12 94
39 54
54 42
20 85
28 65
77 40
10 26
72 5
36 18
64 68
17 62
32 72
65 13
36 61
50 20
74 61
77 67
26 63
32 28
22 47
11 86
71 92
58 18
93 46
84 36
92 89
56 47
80 96
94 42
33 31
93 97
20 15...

output:

713
1 98 100 2
1 90 83 2
1 73 55 7
1 48 43 7
1 39 40 8
1 33 34 2
1 8 12 3
1 3 9 7
2 98 100 3
2 90 83 8
2 54 77 6
2 52 64 4
2 40 48 4
2 39 43 12
2 33 34 6
2 10 31 8
2 3 11 4
3 99 95 6
3 98 94 4
3 97 90 8
3 92 88 9
3 91 83 10
3 89 75 12
3 86 71 25
3 80 65 6
3 78 63 4
3 74 61 11
3 69 60 31
3 62 57 6
3 ...

result:

ok n=100

Test #32:

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

input:

100 430
76 11
76 46
72 19
70 83
76 93
28 94
95 6
72 92
72 20
13 61
28 92
15 84
72 70
13 72
89 49
15 79
76 32
90 60
95 97
13 49
76 35
95 66
76 71
90 85
89 48
90 37
90 79
70 10
76 38
95 83
28 17
90 63
70 98
70 29
90 46
95 100
13 84
13 62
15 82
28 30
90 9
70 7
95 30
72 89
70 34
89 80
95 37
89 51
13 5
9...

output:

-1

result:

ok n=100

Test #33:

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

input:

100 4106
52 90
31 51
7 15
5 96
24 27
1 40
37 27
53 71
3 96
6 10
94 92
33 17
38 42
31 2
29 14
68 63
84 10
45 93
31 94
66 68
61 94
45 83
37 45
36 14
67 15
80 56
82 39
36 75
18 15
75 89
91 15
83 25
43 8
93 10
51 56
35 40
22 74
81 52
78 16
33 94
87 23
88 41
69 2
16 63
91 6
22 89
28 6
38 40
39 92
61 70
3...

output:

502
1 87 97 2
1 86 66 2
1 50 64 8
1 43 60 4
2 99 97 8
2 87 37 6
2 45 28 3
2 34 22 6
2 21 9 5
3 64 97 5
3 50 85 10
3 45 60 6
3 43 9 10
4 87 86 7
4 54 85 8
4 45 64 11
4 34 37 8
4 21 9 12
5 87 97 10
5 86 60 7
5 85 37 10
5 45 28 7
5 34 9 13
6 66 85 10
6 45 67 9
6 34 64 12
6 28 60 11
6 21 9 20
7 50 97 14...

result:

ok n=100

Test #34:

score: 0
Accepted
time: 17ms
memory: 3960kb

input:

1000 142543
300 662
256 12
426 265
168 992
660 315
493 762
89 304
856 178
307 193
693 212
707 246
262 1000
914 725
901 109
707 663
116 797
218 918
598 979
437 334
167 825
731 556
673 851
870 516
834 781
353 400
703 864
261 683
899 141
418 183
661 895
293 921
673 706
325 636
710 73
531 332
464 411
22...

output:

-1

result:

ok n=1000

Test #35:

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

input:

1000 178041
497 424
9 659
747 832
433 668
51 810
29 919
469 449
57 400
574 495
196 68
708 134
686 343
653 896
434 700
89 777
376 46
197 28
311 62
359 778
201 729
596 489
255 157
277 372
426 562
243 343
990 249
198 806
683 340
734 727
555 615
182 190
395 527
397 354
190 301
354 475
261 696
119 187
92...

output:

-1

result:

ok n=1000

Test #36:

score: 0
Accepted
time: 77ms
memory: 5660kb

input:

1000 329058
799 494
38 849
25 833
336 645
577 722
178 79
881 994
809 98
959 430
738 613
748 833
317 137
988 571
284 952
210 348
894 832
797 263
873 309
191 464
192 922
772 410
270 62
578 217
283 991
195 531
998 517
6 994
410 421
874 260
638 366
307 652
105 922
742 367
751 56
575 705
250 684
836 511
...

output:

94082
1 996 990 3
1 988 986 4
1 980 975 2
1 973 974 4
1 966 972 3
1 964 967 5
1 945 962 2
1 944 957 2
1 941 938 6
1 918 913 5
1 895 904 9
1 890 902 3
1 876 898 9
1 858 878 7
1 854 871 9
1 841 836 5
1 827 832 6
1 826 823 9
1 812 820 3
1 811 818 7
1 809 808 3
1 779 806 7
1 776 801 2
1 771 795 8
1 747 ...

result:

ok n=1000

Test #37:

score: 0
Accepted
time: 18ms
memory: 3692kb

input:

700 118864
393 254
361 243
307 538
393 47
635 292
132 684
270 448
303 534
216 214
250 9
547 160
360 102
340 280
134 536
424 127
596 179
14 531
459 107
157 440
107 200
511 93
89 43
639 281
395 613
141 546
444 186
49 546
195 137
694 217
694 79
219 660
319 679
398 25
529 207
74 257
571 28
303 607
434 4...

output:

-1

result:

ok n=700

Test #38:

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

input:

700 166244
142 336
398 620
463 650
98 529
518 118
93 166
583 244
48 390
216 584
373 19
613 674
428 120
410 600
19 178
41 257
41 555
495 251
261 422
220 77
472 256
382 274
190 352
406 419
588 161
207 334
355 102
148 34
530 648
660 623
559 596
35 178
226 525
85 413
123 491
192 215
459 326
339 241
165 ...

output:

43843
1 690 700 3
1 673 699 2
1 658 679 5
1 654 675 9
1 650 667 8
1 619 646 2
1 615 643 13
1 612 633 2
1 608 631 4
1 589 622 4
1 572 611 5
1 571 599 2
1 570 582 2
1 542 580 2
1 536 568 3
1 532 560 2
1 518 559 4
1 499 541 5
1 479 539 20
1 472 531 3
1 460 513 5
1 445 511 2
1 439 494 2
1 428 485 8
1 41...

result:

ok n=700

Test #39:

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

input:

700 181048
343 61
239 523
29 461
7 542
82 585
520 666
88 46
191 501
624 368
559 567
647 267
149 34
458 321
388 574
167 304
418 376
354 289
129 215
143 455
408 187
37 436
260 455
467 12
691 380
93 369
88 225
419 637
463 199
194 172
657 81
162 592
497 301
581 665
441 63
618 492
178 540
438 63
47 16
32...

output:

36460
1 700 698 20
1 697 694 5
1 692 693 4
1 686 690 7
1 683 685 4
1 680 684 3
1 675 681 5
1 674 669 17
1 672 666 2
1 671 658 4
1 667 657 5
1 664 653 2
1 663 652 5
1 662 651 6
1 656 649 5
1 654 643 37
1 645 639 5
1 640 638 5
1 633 635 3
1 630 634 17
1 623 631 7
1 610 628 5
1 599 627 6
1 597 626 3
1 ...

result:

ok n=700

Test #40:

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

input:

700 183148
648 372
284 392
197 636
424 400
34 369
367 419
344 458
236 192
297 358
229 94
680 295
175 416
685 516
542 549
553 338
425 254
519 501
220 146
600 137
440 35
365 674
213 267
310 665
678 18
386 448
388 467
191 40
460 675
427 214
683 387
301 445
513 320
378 257
336 541
8 235
542 477
682 43
2...

output:

34688
1 700 698 5
1 694 696 12
1 692 695 5
1 689 688 5
1 687 682 21
1 683 678 10
1 677 676 12
1 672 667 2
1 663 666 3
1 662 656 3
1 658 652 5
1 657 641 6
1 651 639 10
1 648 629 5
1 646 624 12
1 645 620 2
1 644 614 10
1 632 607 5
1 631 603 12
1 630 601 10
1 627 600 12
1 626 594 6
1 621 590 12
1 619 5...

result:

ok n=700

Test #41:

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

input:

800 26277
664 528
664 612
558 54
766 451
52 97
118 656
13 604
121 257
732 95
675 739
372 490
297 626
351 270
177 367
500 633
359 383
255 47
664 663
675 193
766 370
749 79
420 341
459 697
664 685
696 685
162 577
718 614
756 433
205 436
232 257
420 663
391 400
500 569
541 706
665 120
557 784
232 381
3...

output:

-1

result:

ok n=800

Test #42:

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

input:

800 53746
397 616
781 4
288 657
430 216
532 6
430 649
2 39
61 196
526 271
767 127
457 73
700 378
538 287
345 686
235 79
557 762
750 410
185 530
475 379
733 462
168 748
60 639
496 680
446 311
169 717
626 292
122 364
450 246
761 785
365 356
763 620
795 113
185 380
768 363
345 611
286 518
267 412
185 7...

output:

-1

result:

ok n=800

Test #43:

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

input:

800 61737
666 619
397 336
689 447
203 469
431 587
363 226
653 287
313 184
24 36
560 508
660 25
635 395
748 330
63 281
603 373
340 760
799 564
302 762
381 434
278 541
225 74
339 538
633 647
43 198
210 341
243 342
27 447
660 78
271 743
340 243
381 423
529 538
364 98
210 224
548 297
653 118
403 129
748...

output:

-1

result:

ok n=800

Test #44:

score: 0
Accepted
time: 51ms
memory: 4556kb

input:

800 208781
679 234
339 713
52 125
626 741
628 281
611 392
431 697
418 608
717 298
523 593
790 262
642 770
534 794
312 502
470 731
463 639
362 484
518 468
474 97
406 381
786 388
84 282
237 476
202 555
358 680
110 179
463 239
796 340
408 318
230 539
76 629
362 447
309 28
512 167
83 384
126 800
204 317...

output:

61132
1 789 796 6
1 736 791 3
1 729 783 5
1 722 776 2
1 711 769 2
1 708 755 2
1 707 748 8
1 701 735 3
1 699 728 5
1 693 717 2
1 686 706 12
1 681 703 11
1 674 660 3
1 663 656 3
1 658 642 2
1 651 625 2
1 647 608 2
1 639 604 3
1 638 596 6
1 633 583 2
1 628 582 4
1 614 581 7
1 602 570 2
1 599 569 3
1 59...

result:

ok n=800

Test #45:

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

input:

900 398523
225 110
157 724
694 690
106 826
327 824
86 34
428 654
402 806
336 799
273 365
137 73
466 692
461 752
116 398
547 230
604 399
874 212
542 878
131 167
20 265
521 212
700 674
637 62
624 186
24 418
61 115
339 501
360 392
389 436
592 677
128 320
270 642
880 649
210 397
561 306
53 219
570 137
7...

output:

2956
1 896 769 13
1 544 353 5
2 769 472 11
2 544 71 4
3 765 849 4
3 639 721 5
3 472 176 4
3 138 71 5
4 896 849 5
4 639 353 8
4 544 176 14
4 472 138 5
5 896 769 16
5 627 721 14
5 544 138 15
5 176 71 8
6 896 544 10
6 849 353 15
6 765 138 10
6 639 71 13
7 896 721 8
7 627 138 12
7 544 71 10
8 849 721 18...

result:

ok n=900

Test #46:

score: 0
Accepted
time: 25ms
memory: 3856kb

input:

900 175150
25 208
14 514
879 562
352 487
4 259
353 338
613 221
435 312
286 873
756 40
518 304
56 233
596 631
788 821
511 75
601 817
851 396
889 247
142 346
145 763
876 1
890 796
12 334
219 25
499 334
65 572
553 455
826 780
435 715
376 98
895 80
883 210
175 738
27 768
775 332
254 506
820 258
840 159
...

output:

-1

result:

ok n=900

Test #47:

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

input:

900 72704
357 590
502 896
200 606
898 728
712 593
311 407
898 859
366 115
693 496
291 370
156 642
462 482
878 475
47 413
380 715
541 747
557 478
171 777
776 543
717 307
201 477
682 644
515 896
412 582
677 97
129 81
878 210
595 836
459 567
137 124
322 709
898 736
366 430
298 120
366 589
280 613
69 28...

output:

-1

result:

ok n=900

Test #48:

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

input:

900 387170
42 441
530 66
162 142
568 695
389 788
803 383
426 813
250 679
145 367
667 569
397 817
830 261
139 405
839 224
489 193
697 1
299 754
850 636
809 785
691 148
759 234
359 272
67 157
287 769
853 166
40 153
711 712
568 311
197 536
620 120
127 329
255 860
794 669
860 454
231 60
702 179
574 841
...

output:

9691
1 658 858 5
1 556 782 8
1 554 776 3
1 488 670 8
1 479 664 2
1 387 481 3
1 123 435 3
1 116 406 2
1 64 327 5
1 52 303 3
2 858 706 3
2 776 682 10
2 658 664 4
2 556 630 5
2 554 527 8
2 488 303 9
2 445 218 9
2 287 150 5
2 64 43 10
2 4 8 7
3 658 776 6
3 630 706 4
3 582 682 6
3 556 670 25
3 445 506 6
...

result:

ok n=900

Test #49:

score: 0
Accepted
time: 77ms
memory: 4568kb

input:

1000 406455
9 241
474 877
884 404
468 8
181 866
893 269
225 707
820 961
619 36
112 872
359 821
640 330
680 848
103 19
336 92
769 681
611 714
301 760
676 421
119 257
146 513
87 707
379 455
358 356
708 876
347 122
298 771
570 631
843 201
338 5
436 701
797 530
842 488
848 529
644 925
388 298
596 627
62...

output:

54124
1 971 982 3
1 963 973 5
1 926 972 2
1 894 960 2
1 868 950 9
1 861 910 2
1 845 875 14
1 806 841 3
1 722 839 3
1 718 833 5
1 704 832 6
1 694 819 3
1 687 805 5
1 683 788 8
1 679 781 12
1 653 780 15
1 638 764 5
1 626 759 10
1 615 748 3
1 592 743 7
1 585 669 5
1 541 640 6
1 536 612 4
1 509 589 6
1 ...

result:

ok n=1000

Test #50:

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

input:

1000 488020
67 263
700 688
397 848
658 212
703 330
166 785
606 740
474 760
634 197
121 183
140 885
359 288
241 677
969 867
609 74
590 223
837 496
23 320
780 321
873 217
726 866
7 514
120 616
985 470
177 709
219 599
902 55
587 770
25 303
680 552
874 115
541 878
648 566
216 352
639 51
244 232
383 337
...

output:

6142
1 931 933 7
1 914 884 8
1 902 768 2
1 814 676 10
1 804 538 9
1 595 387 7
1 280 107 16
1 112 6 3
2 914 933 10
2 902 768 8
2 884 676 5
2 471 595 4
2 398 538 5
2 280 387 6
2 77 112 4
3 933 884 5
3 595 768 4
3 471 676 12
3 280 580 8
4 931 814 5
4 884 768 9
4 804 676 13
4 595 580 9
4 398 112 19
4 11...

result:

ok n=1000