QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#142934#6543. Visiting FriendSorahISAAC ✓917ms161084kbC++2010.2kb2023-08-20 05:59:332023-08-20 05:59:36

Judging History

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

  • [2023-08-20 05:59:36]
  • 评测
  • 测评结果:AC
  • 用时:917ms
  • 内存:161084kb
  • [2023-08-20 05:59:33]
  • 提交

answer

#ifndef SorahISA
#define SorahISA
#include SorahISA __FILE__ SorahISA

namespace VBCC {

Vec<2, int> adj, bcc; // 1-base
vector<int> low, dfn;
int Time;
vector<int> bcc_id;
int bcc_cnt; // 1-base
vector<int> is_cut; // whether is av
vector<int> is_cir;
vector<int> st;
int top;

int n, lgmx;
Vec<2, int> badj, banc;
vector<int> bdep, bsz;

void dfs(int u, int pa = -1) {
    int child = 0;
    low[u] = dfn[u] = ++Time;
    st[top++] = u;
    for (int v : adj[u]) {
        if (!dfn[v]) {
            dfs(v, u), ++child;
            low[u] = min(low[u], low[v]);
            if (dfn[u] <= low[v]) {
                is_cut[u] = 1, ++bcc_cnt;
                int t;
                do {
                    bcc_id[t = st[--top]] = bcc_cnt;
                    bcc[bcc_cnt].eb(t);
                } while (t != v);
                bcc_id[u] = bcc_cnt;
                bcc[bcc_cnt].eb(u);
            }
        } else if (dfn[v] < dfn[u] && v != pa) {
            low[u] = min(low[u], dfn[v]);
        }
    }
    if (pa == -1 && child < 2) is_cut[u] = 0;
}

void add_edge(int u, int v) {
    adj[u].eb(v), adj[v].eb(u);
}

void init(int _n) {
    n = _n;
    lgmx = __lg(2*n) + 1;

    Time = bcc_cnt = top = 0;
    adj.assign(n+1, 0);
    bcc.assign(n+1, 0);
    low.assign(n+1, 0);
    dfn.assign(n+1, 0);
    bcc_id.assign(n+1, 0);
    is_cut.assign(n+1, 0);
    is_cir.assign(2*n+1, 0); 
    st.assign(n+1, 0);

    badj.assign(2*n+1, 0);
    banc = Vec<2, int>(2*n+1, lgmx, 0);
    bdep.assign(2*n+1, 0);
    bsz.assign(2*n+1, 0);
}

void solve() {
    for (int i = 1; i <= n; ++i) {
        if (!dfn[i]) dfs(i);
    }
    /// block-cut tree
    for (int i = 1; i <= n; ++i) {
        if (is_cut[i]) bcc_id[i] = ++bcc_cnt, is_cir[bcc_cnt] = 1;
        ++bsz[bcc_id[i]];
    }
    for (int i = 1; i <= bcc_cnt && !is_cir[i]; ++i) {
        for (int j : bcc[i]) {
            if (is_cut[j]) badj[i].eb(bcc_id[j]), badj[bcc_id[j]].eb(i);
        }
    }
}

void dfs_init_bct(int now, int lst = 0) {
    bdep[now] = bdep[lst] + 1;
    banc[now][0] = lst;
    for (int x : badj[now]) {
        if (x == lst) continue;
        dfs_init_bct(x, now);
        bsz[now] += bsz[x];
    }
}

void build_lca_bct() {
    for (int lay = 1; lay < lgmx; ++lay) {
        for (int i = 1; i <= 2*n; ++i) {
            banc[i][lay] = banc[ banc[i][lay-1] ][lay-1];
        }
    }
}

pii lca_bct(int u, int v) {
    if (bdep[u] < bdep[v]) swap(u, v);
    for (int lay = lgmx-1; lay >= 0; --lay) {
        if ((bdep[u] - bdep[v] - 1) >> lay & 1) u = banc[u][lay];
    }
    if (banc[u][0] == v) return {v, u};
    u = banc[u][0];
    
    for (int lay = lgmx-1; lay >= 0; --lay) {
        if (banc[u][lay] != banc[v][lay]) u = banc[u][lay], v = banc[v][lay];
    }
    return {banc[u][0], -1};
}

int get_subsz_bct(int rt, int v) {
    rt = bcc_id[rt], v = bcc_id[v];
    auto [lca, son] = lca_bct(rt, v);
    if (lca != v) return bsz[v];
    else return n - bsz[son];
}

} /// end of namespace VBCC

void solve() {
    int N, M; cin >> N >> M;
    
    VBCC::init(N);
    for (int i = 0, u, v; i < M; ++i) cin >> u >> v, VBCC::add_edge(u, v);
    VBCC::solve();
    
    VBCC::dfs_init_bct(1);
    VBCC::build_lca_bct();
    
    // debug(VBCC::bcc_id);
    // debug(VBCC::badj);
    // debug(VBCC::bsz);
    // debug(VBCC::is_cut);
    
    int Q; cin >> Q;
    for (int q = 1; q <= Q; ++q) {
        int u, v; cin >> u >> v;
        int ans = N;
        if (VBCC::is_cut[u]) ans -= VBCC::get_subsz_bct(v, u) - 1;
        if (VBCC::is_cut[v]) ans -= VBCC::get_subsz_bct(u, v) - 1;
        cout << ans << "\n";
    }
}

int32_t main() {
    fastIO();
    
    int t = 1; cin >> t;
    for (int _ = 1; _ <= t; ++_) {
        // cout << "Case #" << _ << ": ";
        solve();
    }
    
    return 0;
}

#else

#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define double __float80
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;

// #define X first
// #define Y second
#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())

template <size_t D, typename T> struct Vec : vector<Vec<D-1, T>> {
    static_assert(D >= 1, "Vector dimension must be greater than zero!");
    template <typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D-1, T>>(n, Vec<D-1, T>(args...)) {}
};

template <typename T> struct Vec<1, T> : vector<T> {
    Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {}
};

template <class F>
inline constexpr decltype(auto) lambda_fix(F&& f) {
    return [f = std::forward<F>(f)](auto&&... args) {
        return f(f, std::forward<decltype(args)>(args)...);
    };
}

#ifdef local
#define fastIO() void()
#define debug(...) \
    _color.emplace_back("\u001b[31m"), \
    fprintf(stderr, "%sAt [%s], line %d: (%s) = ", _color.back().c_str(), __FUNCTION__, __LINE__, #__VA_ARGS__), \
    _do(__VA_ARGS__), _color.pop_back(), \
    fprintf(stderr, "%s", _color.back().c_str())
deque<string> _color{"\u001b[0m"};

template <typename T> concept is_string = is_same_v<T, string&> or is_same_v<T, const string&>;
template <typename T> concept is_iterable = requires (T _t) {begin(_t);};

template <typename T> inline void _print_err(T &&_t);
template <typename T> inline void _print_err(T &&_t) requires is_iterable<T> and (not is_string<T>);
template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(const tuple<U...> &);
template <size_t I = 0, typename ...U> inline typename enable_if<I <  sizeof...(U), void>::type _print_err(const tuple<U...> &_t);
template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(tuple<U...> &);
template <size_t I = 0, typename ...U> inline typename enable_if<I <  sizeof...(U), void>::type _print_err(tuple<U...> &_t);
template <typename T, typename U> ostream& operator << (ostream &os, const pair<T, U> &_tu);

inline void _do() {cerr << "\n";};
template <typename T> inline void _do(T &&_t) {_print_err(_t), cerr << "\n";}
template <typename T, typename ...U> inline void _do(T &&_t, U &&..._u) {_print_err(_t), cerr << ", ", _do(_u...);}
#else
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define debug(...) void()
#endif

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline int getRand(int L, int R) {
    if (L > R) swap(L, R);
    return (int)(rng() % ((uint64_t)R - L + 1) + L);
}

template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}

/// below are Fast I/O and _print_err templates ///

/*
/// Fast I/O by FHVirus ///
/// https://fhvirus.github.io/blog/2020/fhvirus-io/ ///

#include <unistd.h>

const int S = 65536;

int OP = 0;
char OB[S];

inline char RC() {
    static char buf[S], *p = buf, *q = buf;
    return p == q and (q = (p = buf) + read(0, buf, S)) == buf ? -1 : *p++;
}

inline int RI() {
    static char c;
    int a;
    while (((c = RC()) < '0' or c > '9') and c != '-' and c != -1);
    if (c == '-') {
        a = 0;
        while ((c = RC()) >= '0' and c <= '9') a *= 10, a -= c ^ '0';
    }
    else {
        a = c ^ '0';
        while ((c = RC()) >= '0' and c <= '9') a *= 10, a += c ^ '0';
    }
    return a;
}

inline void WI(int n, char c = '\n') {
    static char buf[20], p;
    if (n == 0) OB[OP++] = '0';
    p = 0;
    if (n < 0) {
        OB[OP++] = '-';
        while (n) buf[p++] = '0' - (n % 10), n /= 10;
    }
    else {
        while (n) buf[p++] = '0' + (n % 10), n /= 10;
    }
    for (--p; p >= 0; --p) OB[OP++] = buf[p];
    OB[OP++] = c;
    if (OP > S-20) write(1, OB, OP), OP = 0;
}

/// Fast I/O by FHVirus ///
/// https://fhvirus.github.io/blog/2020/fhvirus-io/ ///
*/

#ifdef local

template <typename T> inline void _print_err(T &&_t) {cerr << _t;}

template <typename T> inline void _print_err(T &&_t) requires is_iterable<T> and (not is_string<T>) {
    string _tmp_color = _color.back();
    ++_tmp_color[3], _color.emplace_back(_tmp_color);
    cerr << _color.back() << "[";
    for (bool _first = true; auto &_x : _t) {
        if (!_first) cerr << ", ";
        _print_err(_x), _first = false;
    }
    cerr << "]" << (_color.pop_back(), _color.back());
}

template <typename T, typename U> ostream& operator << (ostream &os, const pair<T, U> &_tu) {
    string _tmp_color = _color.back();
    ++_tmp_color[3], _color.emplace_back(_tmp_color);
    cerr << _color.back() << "(";
    _print_err(_tu.first), cerr << ", ", _print_err(_tu.second);
    cerr << ")" << (_color.pop_back(), _color.back());
    return os;
}

template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(const tuple<U...> &) {
    cerr << ")" << (_color.pop_back(), _color.back());
}

template <size_t I = 0, typename ...U> inline typename enable_if<I <  sizeof...(U), void>::type _print_err(const tuple<U...> &_t) {
    if (!I) {
        string _tmp_color = _color.back();
        ++_tmp_color[3], _color.emplace_back(_tmp_color);
        cerr << _color.back();
    }
    cerr << (I ? ", " : "("), _print_err(get<I>(_t)), _print_err<I+1, U...>(_t);
}

template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(tuple<U...> &) {
    cerr << ")" << (_color.pop_back(), _color.back());
}

template <size_t I = 0, typename ...U> inline typename enable_if<I <  sizeof...(U), void>::type _print_err(tuple<U...> &_t) {
    if (!I) {
        string _tmp_color = _color.back();
        ++_tmp_color[3], _color.emplace_back(_tmp_color);
        cerr << _color.back();
    }
    cerr << (I ? ", " : "("), _print_err(get<I>(_t)), _print_err<I+1, U...>(_t);
}

#endif

#endif

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

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

input:

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

output:

2
4
3
3
5

result:

ok 5 number(s): "2 4 3 3 5"

Test #2:

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

input:

100
10 25
7 4
1 10
7 2
3 4
5 7
9 10
10 5
8 10
6 7
9 1
4 2
2 6
8 5
6 9
5 9
7 1
2 1
4 1
9 8
8 3
1 8
4 8
2 10
3 1
3 6
100
6 4
10 8
5 4
7 8
3 10
5 9
6 9
6 8
2 10
10 9
6 9
1 8
3 6
10 9
1 4
10 8
1 6
5 1
5 10
9 1
3 5
8 7
3 2
3 9
2 9
9 4
2 10
8 4
6 2
2 1
7 4
3 6
6 5
10 6
1 4
5 1
7 10
7 1
8 5
3 8
7 5
3 9
5 4...

output:

10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
...

result:

ok 10000 numbers

Test #3:

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

input:

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

output:

10
9
10
10
10
10
10
9
10
10
10
9
10
10
7
10
10
9
8
2
2
10
8
10
10
10
2
8
8
10
8
8
8
10
8
10
7
10
10
10
10
8
10
9
9
10
9
10
10
10
10
10
10
10
10
10
10
10
9
2
8
10
10
10
10
10
10
2
10
10
10
9
8
9
10
8
8
10
10
10
10
10
10
10
10
2
9
9
9
8
9
8
10
10
2
9
10
10
9
10
9
6
7
9
9
9
10
9
5
7
5
10
9
9
9
10
10
6
...

result:

ok 10000 numbers

Test #4:

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

input:

100
100 100
80 78
78 26
52 35
72 97
81 95
93 15
94 72
43 61
12 78
33 93
61 16
58 88
40 61
96 35
99 19
39 31
56 99
62 26
69 51
70 3
9 94
42 61
32 44
56 89
62 72
90 43
61 24
2 77
39 32
34 20
45 87
73 77
86 69
61 81
57 83
34 82
89 92
25 52
90 97
80 21
46 81
60 72
39 6
59 68
59 17
57 3
63 70
21 89
54 63...

output:

99
94
99
100
100
100
99
96
96
100
100
97
99
2
100
95
77
21
100
99
78
89
98
96
96
100
79
99
100
99
98
100
92
99
98
100
84
97
4
94
75
100
89
100
100
97
96
99
100
96
94
93
100
100
100
78
100
72
88
89
99
81
97
91
99
93
100
92
98
80
93
79
99
96
99
79
94
96
77
21
100
9
100
91
99
99
94
2
99
90
91
94
96
99
...

result:

ok 10000 numbers

Test #5:

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

input:

100
100 99
63 30
14 58
2 19
76 62
66 13
85 91
89 47
25 35
60 55
4 28
13 7
29 47
30 22
84 76
85 35
37 67
10 13
63 26
80 70
70 73
4 81
90 60
56 44
42 44
46 42
89 95
10 61
84 27
35 69
26 67
47 16
11 78
66 68
45 82
60 80
70 30
96 31
48 60
81 48
96 5
89 96
92 100
96 39
73 78
94 35
33 41
98 27
13 80
84 46...

output:

78
100
86
78
37
99
95
95
95
89
95
100
100
24
38
26
83
100
100
80
2
100
78
93
93
100
98
100
66
98
95
99
97
93
100
95
95
97
95
100
95
96
60
100
86
98
99
99
96
92
93
100
7
100
97
99
84
99
98
98
7
94
97
97
100
97
96
98
100
66
95
92
100
42
99
38
96
94
100
99
96
36
98
90
95
91
91
100
84
99
100
94
99
100
1...

result:

ok 300000 numbers

Test #6:

score: 0
Accepted
time: 534ms
memory: 135576kb

input:

1
200000 200005
143434 88006
153771 154874
66423 170692
146283 6601
155961 164596
168635 18442
76196 80698
111864 77497
161981 64846
118578 76074
68608 192123
96367 47681
140827 119456
23398 117688
167600 79026
117829 18397
187735 145208
47404 38801
76057 195982
181616 66442
131190 175267
78809 1194...

output:

199996
199986
199987
200000
199998
198266
199998
199998
199976
200000
199998
199999
199991
199996
200000
199501
199999
200000
199986
199997
199999
200000
200000
199992
199952
200000
199993
199991
199993
199997
199914
199970
199998
199797
199040
199997
199974
199974
199934
199990
200000
199968
199995...

result:

ok 500000 numbers

Test #7:

score: 0
Accepted
time: 917ms
memory: 161084kb

input:

1
200000 199999
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
5...

output:

48502
122460
3767
146420
86744
28217
16598
5399
54778
83557
17649
10101
112051
18579
28563
113205
82064
10264
162062
162945
142566
85823
133773
113791
32009
88269
35701
34455
3056
45080
130814
123345
129934
18437
17391
18891
5653
47598
31737
71696
62081
29991
164467
66848
2395
109684
115606
61144
86...

result:

ok 500000 numbers

Test #8:

score: 0
Accepted
time: 596ms
memory: 151640kb

input:

1
200000 299998
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
5...

output:

157194
124118
200000
169308
106089
200000
176622
200000
162310
200000
200000
10101
200000
18579
200000
200000
109182
46713
197013
162945
191814
200000
200000
200000
32009
88269
200000
200000
112554
153502
176802
200000
178256
200000
17391
200000
5653
182450
200000
125832
62081
200000
200000
142774
2...

result:

ok 500000 numbers

Test #9:

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

input:

100
20 28
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
1 3
3 5
5 7
7 9
9 11
11 13
13 15
15 17
17 19
100
3 2
13 10
15 5
4 9
15 7
5 10
12 6
17 5
4 5
19 12
7 8
18 10
6 10
1 8
15 14
16 1
14 17
3 7
6 4
11 7
2 10
10 2
2 12
6 11
19 10
7 10
15 6
11 8
2 3
1...

output:

3
13
11
9
9
16
20
13
5
19
14
20
20
20
15
20
17
5
20
5
20
20
20
11
19
14
15
11
3
20
5
7
20
20
14
18
7
3
20
20
11
17
11
7
20
20
20
18
13
8
18
10
5
17
3
20
16
20
20
5
20
9
12
17
9
20
19
9
5
17
9
12
4
16
20
20
3
5
17
13
20
5
20
5
9
20
15
10
20
11
20
20
9
20
19
13
7
20
20
20
20
13
7
20
12
19
9
5
20
11
9
...

result:

ok 10000 numbers

Test #10:

score: 0
Accepted
time: 264ms
memory: 132868kb

input:

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

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 500000 numbers

Test #11:

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

input:

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

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 200005 numbers

Test #12:

score: 0
Accepted
time: 264ms
memory: 132952kb

input:

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

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 500000 numbers

Test #13:

score: 0
Accepted
time: 90ms
memory: 5140kb

input:

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

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 300000 numbers

Test #14:

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

input:

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

output:

2
4
3
3
5

result:

ok 5 number(s): "2 4 3 3 5"

Test #15:

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

input:

1
2 1
1 2
1
2 1

output:

2

result:

ok 1 number(s): "2"