QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#415620#6559. A Tree and Two Edgesngpin04#AC ✓1789ms13656kbC++146.8kb2024-05-21 06:17:182024-05-21 06:17:19

Judging History

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

  • [2024-05-21 06:17:19]
  • 评测
  • 测评结果:AC
  • 用时:1789ms
  • 内存:13656kb
  • [2024-05-21 06:17:18]
  • 提交

answer

#include <bits/stdc++.h>
#define fi first 
#define se second
#define mp make_pair
#define lb lower_bound
#define pb push_back
#define bit(n) (1LL << (n))
#define getbit(x, i) (((x) >> (i)) & 1)
#define pii pair <int, int>
#define ALL(x) x.begin(), x.end()
using namespace std;
const int oo = 1e9;
const long long ooo = 1e18;

template<typename T1, typename T2> bool mini(T1 &a, T2 b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int lim = 5e4 + 5;
struct disjoint_set {
    int h[lim], sz[lim];
    disjoint_set() {
        memset(h, -1, sizeof(h));
        fill(sz, sz + lim, 1);
    }
    int fh(int nd) {
        return h[nd] == -1 ? nd : h[nd] = fh(h[nd]);
    }
    bool same_par(int x, int y) {
        return fh(x) == fh(y);
    }
    bool merge(int x, int y) {
        x = fh(x), y = fh(y);
        if(x != y) {
            if(sz[x] < sz[y])
                swap(x, y);
            sz[x] += sz[y];
            h[y] = x;
        }
        return x != y;
    }
};
vector<int> edges[lim];
int disc[lim], low[lim], t;
vector<pair<int, int>> bridges;
void tarjan(int nd, int pr = -1) {
    disc[nd] = low[nd] = t++;
    for(auto x : edges[nd]) {
        if(x == pr)
            continue;
        if(disc[x] == -1) {
            tarjan(x, nd);
            low[nd] = min(low[nd], low[x]);
        }
        else {
            low[nd] = min(low[nd], disc[x]);
        }
        if(low[x] > disc[nd])   
            bridges.pb(mp(nd, x));
    }   
}
bool vis[lim];
void dfs(int nd, int origin, vector<pair<int, int>> &a) {
    vis[nd] = 1;
    // cerr << "dfs " << origin << " " << nd << endl;
    a.pb(mp(nd, origin));
    for(auto i : edges[nd]) {
        if(!vis[i]) {
            dfs(i, origin, a);
        }
    }

}
int main() {
    memset(disc, -1, sizeof(disc));
    memset(low, -1, sizeof(low));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<pair<int, int>> adj;
    for(int i = 1; i <= n + 1; ++i) {
        int u, v;
        cin >> u >> v;
        edges[u].pb(v);
        edges[v].pb(u);
        adj.pb(mp(u, v));
    }
    tarjan(1);
    for(auto &p : bridges) {
        if(p.fi > p.se)
            swap(p.fi, p.se);
    }
    sort(bridges.begin(), bridges.end());
    disjoint_set dsu;
    for(auto p : adj) {
        if(p.fi > p.se)
            swap(p.fi, p.se);
        if(!binary_search(bridges.begin(), bridges.end(), p)) {
            // not bridge
            dsu.merge(p.fi, p.se);
        }
    }
    // nbd -> non bridge degree
    int nbd[n + 1];
    memset(nbd, 0, sizeof(nbd));
    // cerr << "nbd" << endl;
    for(int i = 1; i <= n; ++i) {
        for(auto x : edges[i]) {
            if(dsu.same_par(i, x)) {
                ++nbd[i];
            }
        }
        // cerr << nbd[i] << " ";
    }
    // cerr << endl;
    // fi -> node to find
    // se -> last node in the important cc
    vector<vector<pair<int, int>>> v;
    bool used[n + 1];
    memset(used, 0, sizeof(used));
    for(int i = 1; i <= n; ++i) {
        // cerr << dsu.fh(i) << " " << dsu.sz[dsu.fh(i)] << endl;
        if(dsu.sz[dsu.fh(i)] > 1 && !used[dsu.fh(i)]) {
            for(int j = 1; j <= n; ++j)
                edges[j].clear();
            for(auto p : adj) {
                if(p.fi > p.se)
                    swap(p.fi, p.se);
                if(!(dsu.same_par(i, p.fi) && dsu.same_par(i, p.se))) {
                    edges[p.fi].pb(p.se);
                    edges[p.se].pb(p.fi);
                }
            }
            // cerr << "dfs " << i << endl;
            vector<pair<int, int>> cur;
            used[dsu.fh(i)] = 1;
            // find for every other node the original
            memset(vis, 0, sizeof(vis));
            for(int j = 1; j <= n; ++j) {
                if(dsu.fh(j) == dsu.fh(i))
                    dfs(j, j, cur);
            }
            sort(cur.begin(), cur.end());
            v.pb(cur);
        }
    }
    for(int i = 1; i <= n; ++i) {
        // cerr << nbd[i] << " ";
        if(nbd[i] == 4) {
            // special special case
            int spec = i;
            disjoint_set dsu;
            for(auto p : adj) {
                if(p.fi != i && p.se != i)
                    dsu.merge(p.fi, p.se);
            }
            while(q--) {
                int x, y;
                cin >> x >> y;
                int res = 1;
                for(auto vec : v) {
                    int ndx = (*lb(vec.begin(), vec.end(), mp(x, 0))).se, ndy = (*lb(vec.begin(), vec.end(), mp(y, 0))).se;
                    // cerr << x << " " << y << " " << ndx << " " << ndy << endl;
                    if(ndx == ndy)
                        res *= 1;
                    else if(nbd[ndx] == 4 || nbd[ndy] == 4 || dsu.same_par(x, y)) 
                        res *= 2;
                    else
                        res *= 4;
                }
                cout << res << endl;
            }
            exit(0);
        }
    }
    if(v.size() == 1) {
        vector<int> spec;
        for(int i = 1; i <= n; ++i) {
            if(nbd[i] == 3)
                spec.pb(i);
        }
        disjoint_set dsu;
        for(auto p : adj) {
            bool valid = 1;
            for(auto x : spec) {
                if(p.fi == x || p.se == x) 
                    valid = 0;
            }
            if(valid) {
                dsu.merge(p.fi, p.se);
            }
        }
        while(q--) {
            int x, y;
            cin >> x >> y;
            int res = 1;
            for(auto vec : v) {
                int ndx = (*lb(vec.begin(), vec.end(), mp(x, 0))).se, ndy = (*lb(vec.begin(), vec.end(), mp(y, 0))).se;
                // cerr << x << " " << y << " " << ndx << " " << ndy << endl;
                if(ndx == ndy)
                    res *= 1;
                else if(nbd[ndx] == 3 || nbd[ndy] == 3 || dsu.same_par(x, y)) 
                    res *= 3;
                else
                    res *= 4;
            }
            cout << res << endl;
        }
        exit(0);
    }
    // cerr << endl;
    while(q--) {
        int x, y;
        cin >> x >> y;
        int res = 1;
        for(auto vec : v) {
            int ndx = (*lb(vec.begin(), vec.end(), mp(x, 0))).se, ndy = (*lb(vec.begin(), vec.end(), mp(y, 0))).se;
            // cerr << ndx << " " << ndy << endl;
            if(ndx == ndy)
                res *= 1;
            else if(nbd[ndx] == 3 || nbd[ndy] == 3)
                res *= 3;
            else if(v.size() == 1)
                res *= 4;
            else
                res *= 2;
        }
        cout << res << endl;
    }
    return 0;
}

详细

Test #1:

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

input:

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

output:

3
3
3
3
3
4

result:

ok 6 lines

Test #2:

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

input:

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

output:

2
2
4
1

result:

ok 4 lines

Test #3:

score: 0
Accepted
time: 870ms
memory: 9476kb

input:

50000 50000
11561 23122
14261 28523
24407 48814
17947 35894
14803 29607
19557 39115
12415 24830
9583 19167
18397 36794
439 878
18040 36080
17150 34300
7922 15845
18938 37877
18625 37250
6459 12919
9818 19636
3579 7158
21323 42646
23882 47764
13603 27207
8353 16707
15907 31814
20935 41871
11686 23372...

output:

4
3
3
4
4
3
1
3
4
1
3
4
3
4
3
3
1
3
3
3
4
4
4
3
3
3
4
3
3
3
1
3
3
3
3
4
4
4
4
3
4
3
3
3
4
3
4
4
4
4
3
4
4
4
4
3
3
3
4
4
4
4
4
4
3
4
3
4
1
4
1
1
4
3
3
4
3
3
1
4
3
3
4
4
3
3
4
4
4
3
4
3
4
4
4
4
4
3
4
3
3
3
1
3
4
4
3
4
3
4
3
3
4
1
4
3
3
3
4
4
4
4
3
3
3
3
3
4
4
4
4
3
3
4
3
4
4
3
3
4
4
4
1
3
3
3
3
4
4
3
...

result:

ok 50000 lines

Test #4:

score: 0
Accepted
time: 893ms
memory: 9332kb

input:

50000 50000
1730 3460
17535 35071
14108 28216
20630 41260
2091 4182
8112 16225
21373 42746
6685 13371
21142 42284
12168 24337
22564 45128
16103 32207
9254 18508
21369 42739
1955 3911
13696 27392
3929 7858
1777 3555
23382 46764
830 1660
17722 35444
11495 22991
10184 20369
13697 27395
24728 49456
4037...

output:

1
1
3
3
3
4
4
4
4
4
3
3
3
4
1
3
4
3
3
1
3
3
4
3
1
4
3
3
4
3
3
4
4
4
1
1
4
1
3
4
3
1
4
4
3
3
3
4
1
4
4
1
3
1
3
3
3
1
1
3
3
3
3
3
4
3
4
4
3
3
4
4
4
3
3
4
4
4
3
4
3
3
3
3
3
3
3
3
4
4
1
4
3
4
1
4
4
4
4
3
4
1
4
4
3
4
3
4
3
4
3
1
4
3
1
1
3
3
4
4
1
3
3
3
4
3
3
4
4
4
4
4
3
3
4
3
4
1
1
3
4
4
3
4
4
3
3
4
4
3
...

result:

ok 50000 lines

Test #5:

score: 0
Accepted
time: 1789ms
memory: 9540kb

input:

50000 50000
21879 43758
12510 25020
2593 5187
16048 32096
9697 19394
12606 25212
3860 7720
8231 16462
23983 47966
10852 21705
6919 13839
1385 2770
4040 8080
14298 28596
22248 44496
4245 8490
14486 28972
11445 22891
21557 43114
20946 41892
23374 46749
78 157
4617 9234
8198 16396
12228 24456
16125 322...

output:

4
2
2
2
4
2
1
2
2
2
4
2
1
2
4
2
2
4
4
4
2
1
4
2
2
4
2
4
2
2
1
4
2
2
1
1
4
4
2
2
2
4
2
4
2
4
4
4
2
2
4
2
2
4
1
4
1
4
4
2
4
4
2
2
2
2
4
2
2
1
2
1
4
2
4
4
4
4
2
2
2
4
4
1
2
1
2
4
4
4
2
2
2
2
4
4
4
4
4
2
4
2
4
4
2
4
4
4
4
4
2
4
2
2
4
4
4
1
2
2
2
4
1
2
4
1
2
2
4
2
4
4
2
4
2
2
4
1
4
1
2
4
2
2
4
4
4
4
4
4
...

result:

ok 50000 lines

Test #6:

score: 0
Accepted
time: 1494ms
memory: 9328kb

input:

50000 50000
1451 2795
8910 29108
638 5810
24117 38535
2769 44109
7603 8789
14090 14819
5315 11076
22885 25853
26110 39470
1513 20322
13635 44414
1284 5229
5998 19700
1872 45691
5872 37168
4991 6456
34921 41632
16532 30269
3118 4987
2732 20486
26292 44061
2054 41607
20367 21071
33204 36717
35801 4725...

output:

2
2
4
4
4
4
4
2
4
4
4
4
4
4
4
2
1
4
4
1
4
4
1
4
4
2
4
2
4
2
1
4
4
4
4
1
1
1
4
2
4
1
4
2
4
1
1
2
2
2
4
4
1
1
1
4
1
1
4
2
4
4
1
4
2
2
4
4
4
2
1
4
4
1
1
4
4
1
2
1
2
1
4
2
1
2
4
2
4
4
4
4
4
1
2
2
1
1
1
4
2
1
4
4
2
4
2
4
4
1
1
4
4
2
2
1
2
1
1
4
4
4
4
4
4
1
1
1
4
2
4
1
2
2
1
4
4
4
4
4
4
1
4
4
2
1
2
2
2
1
...

result:

ok 50000 lines

Test #7:

score: 0
Accepted
time: 1508ms
memory: 9380kb

input:

50000 50000
1106 3307
13115 16051
30404 45806
2295 20076
3525 6384
9118 24628
3288 26835
17933 47506
26180 48256
23161 45529
10483 15545
5252 35302
10105 16247
14301 26402
104 216
562 29098
1517 16503
1494 5468
8057 47252
5582 15425
8766 41483
10952 31098
20891 49612
13088 18868
18880 28314
8650 208...

output:

1
2
4
2
4
4
2
4
2
4
4
4
2
2
2
2
4
2
4
4
4
2
4
1
2
1
4
4
1
2
4
2
1
4
4
4
4
4
2
4
4
4
4
1
2
1
2
1
4
4
2
2
4
4
1
4
4
4
2
2
2
1
4
2
4
2
4
4
4
2
2
4
2
2
1
4
4
2
4
4
4
2
1
4
1
4
4
4
4
4
4
1
2
2
2
4
1
2
1
4
2
4
2
4
4
4
1
4
2
4
4
2
4
2
4
2
4
4
1
4
4
2
1
4
4
4
2
4
2
2
2
2
2
4
4
2
4
4
2
2
4
1
2
1
4
4
2
2
2
4
...

result:

ok 50000 lines

Test #8:

score: 0
Accepted
time: 870ms
memory: 12308kb

input:

50000 50000
36923 36924
2905 2906
20948 20949
17459 17460
37562 37563
48652 48653
19674 19675
5083 5084
18973 18974
6652 6653
14171 14172
10957 10958
29643 29644
18578 18579
8742 8743
28856 28857
3692 3693
9716 9717
26628 26629
10272 10273
3581 3582
5952 5953
8810 8811
48242 48243
49449 49450
22461 ...

output:

3
3
3
4
4
3
4
3
3
4
3
3
4
1
3
3
3
4
4
1
4
3
3
1
4
4
3
3
4
1
4
3
4
3
1
3
3
4
3
3
4
3
4
3
3
4
1
4
4
4
4
3
3
1
4
4
1
3
3
3
3
4
3
3
4
3
4
3
3
3
4
3
4
1
4
4
1
4
4
4
3
4
4
4
3
3
1
3
4
4
4
4
4
3
4
3
4
4
3
1
4
4
3
4
4
1
4
4
4
3
3
4
3
4
4
4
3
3
4
3
3
3
4
4
3
4
3
4
4
3
4
3
3
4
1
4
3
4
4
4
4
4
1
4
4
1
1
4
4
4
...

result:

ok 50000 lines

Test #9:

score: 0
Accepted
time: 866ms
memory: 13656kb

input:

50000 50000
24442 24443
33810 33811
1074 1075
19395 19396
17355 17356
18062 18063
16633 16634
14075 14076
16668 16669
42955 42956
2381 2382
8174 8175
33065 33066
23490 23491
12964 12965
43083 43084
34043 34044
3067 3068
32847 32848
34631 34632
20740 20741
5545 5546
36224 36225
40474 40475
8726 8727
...

output:

3
3
4
4
4
3
4
4
4
4
3
4
4
4
4
4
4
3
4
1
1
3
4
4
3
4
4
4
1
4
3
4
4
4
3
4
4
4
4
4
3
3
4
4
3
4
4
1
3
1
4
4
4
4
1
3
4
4
4
4
1
3
3
4
4
4
4
4
3
4
4
4
4
4
4
4
4
4
4
1
3
4
4
1
4
4
4
4
1
4
1
4
4
1
4
1
3
4
4
4
4
4
3
4
4
4
4
3
3
1
4
3
4
3
3
4
3
4
4
4
4
3
4
4
4
3
4
4
4
4
3
1
4
3
3
3
4
4
4
4
4
4
4
4
3
4
1
3
4
3
...

result:

ok 50000 lines

Test #10:

score: 0
Accepted
time: 901ms
memory: 11944kb

input:

50000 50000
40842 40843
12739 12740
46074 46075
30742 30743
22435 22436
4320 4321
9400 9401
40706 40707
8828 8829
18753 18754
49910 49911
39576 39577
8444 8445
25799 25800
49700 49701
37009 37010
2714 2715
25544 25545
38257 38258
48120 48121
16639 16640
49101 49102
13588 13589
15000 15001
46269 4627...

output:

4
4
3
1
3
4
4
4
4
3
3
4
4
1
3
3
4
3
1
4
3
4
3
3
1
3
3
4
3
4
4
4
3
4
3
4
3
3
4
3
4
4
4
1
3
4
4
4
4
3
3
4
4
4
3
4
3
3
3
4
4
4
3
3
4
4
4
4
3
4
3
1
4
3
3
4
1
4
4
3
3
3
4
3
4
4
1
4
4
4
4
4
3
4
4
4
3
3
4
4
3
3
4
1
4
1
3
4
4
4
3
4
4
1
4
4
1
4
3
4
3
4
4
3
4
3
3
4
3
4
3
4
3
3
4
4
4
3
4
4
4
3
4
3
4
4
1
3
1
3
...

result:

ok 50000 lines

Test #11:

score: 0
Accepted
time: 882ms
memory: 9484kb

input:

50000 50000
8009 12254
22108 22277
5752 17047
4139 8705
1591 4046
29067 29462
14609 40048
465 23331
4440 14716
9607 9722
13461 30905
36645 38691
1569 25431
2752 4554
214 34538
36719 44914
21390 24345
29832 31704
21884 44025
23443 39152
7339 21353
11648 46289
1971 3851
13124 18924
24293 31487
14625 2...

output:

3
3
3
3
1
3
1
3
1
3
3
1
3
1
1
1
1
3
3
3
1
4
3
1
3
3
3
3
3
3
3
1
3
3
4
3
3
1
3
3
1
3
1
1
3
3
4
4
3
1
3
1
4
1
3
3
3
3
3
4
3
3
3
1
3
3
1
3
1
3
3
3
3
3
3
3
3
3
1
3
3
3
3
3
4
4
3
4
1
3
1
4
1
3
1
1
1
1
3
1
3
3
3
3
3
3
1
1
3
1
4
3
3
3
3
3
1
3
3
1
3
3
3
3
3
3
1
1
1
1
1
3
3
3
3
3
3
3
1
1
3
4
1
1
3
4
3
3
1
1
...

result:

ok 50000 lines

Test #12:

score: 0
Accepted
time: 888ms
memory: 9336kb

input:

50000 50000
25911 28394
6660 10841
8387 28553
3683 10256
13802 22801
12147 23011
16188 43369
5992 27667
12961 16775
2715 9516
28953 35973
2983 8072
11231 11882
8072 21167
5834 13733
5340 25884
462 1070
959 27073
809 4568
1345 25432
4809 8997
6625 44504
11148 14179
6983 30617
5970 13330
36575 37652
2...

output:

3
3
4
4
3
4
3
3
3
3
3
3
3
4
3
3
3
3
4
3
4
3
3
3
3
3
3
3
3
3
4
4
3
4
4
1
3
3
4
4
3
4
3
3
3
3
4
3
3
1
4
3
3
3
3
4
3
3
1
3
1
1
3
3
4
3
4
3
3
3
4
1
3
3
3
3
3
1
3
1
3
3
3
4
3
3
3
3
4
3
4
3
3
3
3
3
3
3
3
3
3
4
3
3
4
4
3
3
3
1
3
3
3
4
4
3
3
1
3
3
3
3
3
3
3
3
4
4
3
3
3
3
3
3
3
4
3
4
1
4
4
3
3
3
4
1
4
3
3
3
...

result:

ok 50000 lines

Test #13:

score: 0
Accepted
time: 909ms
memory: 9332kb

input:

50000 50000
42553 43740
18549 40701
3806 34236
10812 24567
1202 22133
944 18780
5622 8617
9734 23242
29968 32325
6567 9568
6845 17190
1949 7833
22214 23070
1384 15280
6170 6561
28119 31703
6100 48374
980 8110
8426 15001
3332 7523
8030 23908
974 5799
7318 11335
14037 15714
13671 20465
43715 47320
210...

output:

1
4
4
1
3
1
4
3
3
1
4
4
3
4
1
4
3
3
4
4
4
4
3
3
4
4
4
4
4
3
1
4
4
3
4
4
1
1
4
1
4
3
4
1
1
4
3
3
1
1
1
3
3
3
4
1
1
1
4
4
3
3
3
3
3
1
1
3
1
3
3
3
1
1
3
4
1
1
1
3
3
3
4
1
3
3
1
3
4
3
4
4
3
4
3
4
3
4
3
3
4
3
3
1
3
4
3
1
4
1
1
3
4
1
3
1
4
4
4
4
1
4
1
4
3
1
1
1
3
3
1
3
3
4
1
1
3
3
3
1
1
3
4
4
4
3
4
3
1
1
...

result:

ok 50000 lines

Test #14:

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

input:

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

output:

3

result:

ok single line: '3'

Test #15:

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

input:

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

output:

2

result:

ok single line: '2'

Test #16:

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

input:

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

output:

2
2
4
2
4
1

result:

ok 6 lines

Test #17:

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

input:

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

output:

2

result:

ok single line: '2'

Test #18:

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

input:

17 8
1 2
2 3
3 4
4 5
1 6
6 7
7 8
8 9
1 10
10 11
11 12
12 13
1 14
14 15
15 16
16 17
5 9
13 17
1 5
2 6
3 7
4 8
5 9
1 8
1 16
2 11

output:

2
2
2
2
2
2
2
4

result:

ok 8 lines

Test #19:

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

input:

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

output:

3
3
3
4

result:

ok 4 lines

Test #20:

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

input:

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

output:

3
4
3
3
3

result:

ok 5 lines

Test #21:

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

input:

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

output:

3
4
3
1
4
3

result:

ok 6 lines

Test #22:

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

input:

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

output:

4
1
3
1
3
3
1

result:

ok 7 lines

Test #23:

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

input:

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

output:

3
3
3
3
3
4
4
3

result:

ok 8 lines

Test #24:

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

input:

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

output:

3
3
3
3
4
3
1
3
4

result:

ok 9 lines

Test #25:

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

input:

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

output:

3
1
3
3
3
4
3
3
1
3

result:

ok 10 lines

Test #26:

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

input:

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

output:

1
1
3
3
3
3
1
3
1
3
1

result:

ok 11 lines

Test #27:

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

input:

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

output:

2
2
2
2
2
2
2
2
4
4
2
2

result:

ok 12 lines

Test #28:

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

input:

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

output:

3
3
3
3
3
3
1
3
3
3
3
3
1

result:

ok 13 lines

Test #29:

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

input:

14 14
1 3
10 12
1 11
3 7
1 4
2 6
3 14
2 9
3 13
5 10
4 8
13 14
1 2
2 8
3 5
9 11
10 12
3 5
1 14
2 7
7 12
2 7
3 5
7 11
9 13
8 14
4 11
5 11
8 12

output:

2
1
1
2
2
1
2
1
1
4
4
2
1
2

result:

ok 14 lines

Test #30:

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

input:

15 15
5 6
10 15
8 10
6 7
2 3
9 14
1 2
9 12
1 5
3 10
2 8
3 4
1 9
6 13
1 14
7 11
2 14
6 11
9 12
5 10
11 15
8 9
4 14
4 10
6 13
4 6
1 8
3 8
8 14
2 11
9 13

output:

2
1
1
2
2
4
4
2
1
2
2
2
4
1
2

result:

ok 15 lines

Test #31:

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

input:

16 16
12 13
2 6
1 4
1 2
3 8
4 10
7 9
2 14
10 15
2 3
6 11
13 16
5 12
1 7
2 5
13 15
3 16
12 16
1 2
13 16
4 12
2 5
5 11
5 16
1 2
3 5
4 9
9 11
13 14
5 12
5 12
5 9
12 16

output:

4
3
3
4
3
3
4
3
4
3
3
3
3
3
4
4

result:

ok 16 lines

Test #32:

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

input:

17 17
4 9
3 14
2 4
2 8
3 10
9 11
3 7
1 3
1 2
4 13
4 5
10 17
2 3
6 12
6 16
5 6
1 10
3 15
4 16
3 6
1 14
3 14
12 15
8 12
2 14
6 13
1 8
14 17
9 17
4 15
12 14
1 6
7 16
10 12
9 17

output:

1
3
3
1
3
1
3
1
3
3
4
3
3
3
3
4
4

result:

ok 17 lines

Test #33:

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

input:

18 18
4 9
3 13
3 4
5 14
1 12
6 11
6 16
1 15
6 14
2 3
2 6
4 7
1 2
1 5
6 8
7 17
1 18
16 17
9 10
1 15
12 17
7 17
12 17
4 14
6 16
4 15
2 9
8 18
3 5
7 17
7 9
2 13
7 15
9 14
6 7
1 9
1 17

output:

1
4
3
4
4
3
4
3
3
4
3
3
3
4
4
3
4
4

result:

ok 18 lines

Test #34:

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

input:

19 19
2 7
6 9
11 19
4 10
8 17
3 6
3 5
8 11
2 18
5 13
1 3
10 13
9 15
12 17
6 16
3 4
4 8
1 2
12 14
6 12
5 11
10 14
4 19
1 3
1 9
3 15
7 19
3 9
4 5
14 18
3 8
11 14
1 4
3 12
1 5
5 16
4 17
14 18
1 17

output:

4
4
3
1
3
3
3
3
3
3
3
3
3
3
3
4
3
3
3

result:

ok 19 lines

Test #35:

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

input:

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

output:

4
3
1
4
3
3
4
1
3
3
3
3
4
3
3
1
4
3
1
4

result:

ok 20 lines

Test #36:

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

input:

100 200
15 84
22 89
29 48
46 59
3 5
33 69
20 77
1 56
2 13
13 60
5 24
24 97
45 52
23 37
8 23
47 99
41 75
7 25
69 70
24 93
18 27
4 51
67 78
5 30
2 3
6 39
1 2
13 16
8 26
73 74
25 28
17 47
70 83
72 79
9 66
15 91
4 10
9 11
24 33
22 29
1 4
4 32
20 41
70 100
43 55
59 89
6 7
2 14
1 90
41 54
13 20
28 98
28 3...

output:

3
3
4
3
4
4
4
1
1
3
3
4
4
4
4
4
4
4
4
4
3
3
3
3
4
4
1
3
4
3
3
3
1
3
3
4
4
4
1
3
3
4
3
3
4
4
3
3
3
3
1
3
4
1
4
4
3
3
1
3
4
3
1
3
3
3
3
4
1
3
3
1
3
3
3
3
3
3
3
4
4
3
3
3
3
4
3
4
4
4
4
4
3
4
3
4
3
4
3
3
4
3
1
3
4
4
4
3
3
3
3
3
1
3
3
4
3
3
4
3
4
4
1
3
3
3
3
4
3
1
3
3
4
4
3
3
3
4
1
3
3
4
3
3
4
3
3
3
3
3
...

result:

ok 200 lines

Test #37:

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

input:

200 100
22 24
21 187
7 13
64 141
7 86
5 55
21 63
162 193
2 28
91 157
109 127
78 152
3 159
12 150
1 4
135 161
39 68
107 198
35 48
118 149
61 147
62 184
18 74
30 80
3 7
113 139
84 179
18 75
7 31
77 129
126 195
53 70
19 37
6 49
22 92
79 117
12 83
54 96
45 58
11 61
18 131
125 197
91 177
157 169
28 56
35...

output:

3
3
3
3
3
3
1
4
3
3
3
3
4
3
3
1
4
3
3
3
1
4
1
1
1
3
3
3
3
3
3
3
3
1
3
4
3
3
3
3
3
4
3
4
4
1
3
3
3
1
3
1
1
1
3
3
3
1
1
3
3
1
1
4
3
1
1
1
1
3
4
4
3
1
3
1
1
3
3
4
4
3
3
4
3
4
1
3
3
3
3
1
1
3
3
3
1
1
3
3

result:

ok 100 lines