QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#730573#2512. Quality MonitoringpenguinmanAC ✓161ms15112kbC++234.4kb2024-11-09 20:43:582024-11-09 20:43:58

Judging History

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

  • [2024-11-09 20:43:58]
  • 评测
  • 测评结果:AC
  • 用时:161ms
  • 内存:15112kb
  • [2024-11-09 20:43:58]
  • 提交

answer

#include <bits/stdc++.h>

#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); i++)
#define rrep(i, n) for(ll i = ll(n) - 1; i >= 0; i--)
#define rrep2(i, n, t) for(ll i = ll(n) - 1; i >= ll(t); i--)
#define all(a) a.begin(), a.end()
#define SZ(a) ll(a.size())
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;

template<typename T>
struct SegmentTree{
    ll N;
    T INF;
    vector<T> node;
    SegmentTree(ll n, T INF_):INF(INF_){
        N = 1;
        while(N <= n) N <<= 1;
        node.resize(2*N, INF);
    }
    T compare(T A, T B){
        return max(A, B);
    }
    void update(ll index, T val){
        index += N;
        node[index] = val;
        while(index > 0){
            index >>= 1;
            node[index] = compare(node[index*2], node[index*2+1]);
        }
    }
    T calc(ll left, ll right){
        T ret = INF;
        left += N;
        right += N;
        while(left < right){
            if(left & 1) ret = compare(ret, node[left++]);
            if(right & 1) ret = compare(ret, node[--right]);
            left >>= 1;
            right >>= 1;
        }
        return ret;
    }
};

constexpr ll inf = LLONG_MAX/4;
SegmentTree<P> seg(0, make_pair(-inf, -inf));
ll n;
vvl edge;
vl cnt;
vector<bool> used;

void deactivate(ll now){
    assert(!used[now]);
    seg.update(now, make_pair(-inf, now));
    used[now] = true;
    for(auto next: edge[now]){
        if(used[next]) continue;
        cnt[next]--;
        seg.update(next, make_pair(cnt[next],next));
    }
}

void activate(ll now){
    assert(used[now]);
    seg.update(now, make_pair(cnt[now], now));
    used[now] = false;
    for(auto next: edge[now]){
        if(used[next]) continue;
        cnt[next]++;
        seg.update(next, make_pair(cnt[next],next));
    }
}

ll dfs(ll remain){
    if(remain < 0) return -inf;
    auto p = seg.calc(0, n);
    if(p.first <= 0){
        return remain;
    }
    if(p.first <= 2){
        vl cand;
        rep(_,remain*3){
            p = seg.calc(0, n);
            if(p.first <= 0) break;
            seg.update(p.second, make_pair(-inf, p.second));
            cand.eb(p.second);
        }
        p = seg.calc(0, n);
        if(p.first > 0){
            for(auto s: cand) seg.update(s, make_pair(cnt[s], s));
            return -inf;
        }
        for(auto s: cand){
            if(used[s]) continue;
            ll visited = 0;
            queue<ll> que;
            que.push(s);
            bool isCycle = true;
            used[s] = true;
            while(!que.empty()){
                ll now = que.front(); que.pop();
                if(cnt[now] == 1) isCycle = false;
                visited++;
                for(auto next: edge[now]){
                    if(used[next]) continue;
                    que.push(next);
                    used[next] = true;
                }
            }
            if(isCycle) remain -= (visited+1)/2;
            else remain -= visited/2;
        }
        for(auto s: cand){
            seg.update(s, make_pair(cnt[s], s));
            used[s] = false;
        }
        return remain;
    }
    ll ret = -inf;
    ll now = p.second;
    if(p.first <= remain){
        deactivate(now);
        vl visited;
        for(auto next: edge[now]){
            if(used[next]) continue;
            visited.eb(next);
            deactivate(next);
        }
        ret = max(ret, dfs(remain-p.first));
        reverse(all(visited));
        for(auto next: visited) activate(next);
        activate(now);
    }
    deactivate(now);
    ret = max(ret, dfs(remain-1));
    activate(now);
    return ret;
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    cout << std::fixed << std::setprecision(15);
    ll m; cin >> n >> m;
    edge.resize(n);
    rep(i,m){
        ll x,y; cin >> x >> y;
        edge[x].eb(y);
        edge[y].eb(x);
    }
    cnt.resize(n);
    seg = SegmentTree<P>(n, make_pair(-inf, -inf));
    rep(i,n){
        cnt[i] = SZ(edge[i]);
        seg.update(i, make_pair(cnt[i],i));
    }
    used.resize(n);
    ll ans = n-29+dfs(29);
    if(ans < n-28) ans = -1;
    cout << ans << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 7
1 0
2 3
1 4
1 2
3 1
3 4
0 4

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 130ms
memory: 13708kb

input:

30000 375944
12559 10814
9056 27688
5877 12602
1201 26739
2268 25471
25051 3914
2521 13925
2917 17413
11167 13925
1701 11675
2808 2248
7812 7061
26498 5148
15427 22504
12220 13801
18271 2891
16610 7061
7229 15268
17211 13925
20474 25471
22342 27688
26021 25471
6162 10068
9514 10068
18765 13925
12554...

output:

29977

result:

ok single line: '29977'

Test #3:

score: 0
Accepted
time: 122ms
memory: 13516kb

input:

30000 356945
6424 27639
19167 15771
20217 9301
3509 12368
29642 23652
12026 9763
9162 15680
3708 26697
28749 29578
6123 27616
14643 14603
26017 974
29668 26697
25837 27616
9541 15680
24717 4166
2116 15771
26969 15680
29506 23512
25656 9763
16409 4318
4112 4166
26193 9763
12243 20771
28128 14603
2534...

output:

29978

result:

ok single line: '29978'

Test #4:

score: 0
Accepted
time: 151ms
memory: 14844kb

input:

30000 447182
5045 22932
2607 8671
4458 28955
22008 18570
556 26449
17825 26719
9171 28739
9100 8671
24209 18867
14917 26449
990 28955
4646 18231
17137 263
6245 18552
6298 9776
25093 28739
4187 18570
15563 18867
2408 10636
684 22932
1969 18288
12283 21389
18119 18062
9044 18062
7793 18288
6046 28955
...

output:

29972

result:

ok single line: '29972'

Test #5:

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

input:

30000 449801
20814 1010
22105 26719
24289 17681
20455 12171
3400 11548
25655 18560
25656 8519
20035 11548
5668 23027
6922 9039
11754 17681
29503 12171
29175 16144
12653 22716
1018 11548
25047 8519
25504 4540
15494 13365
6994 8519
2752 20702
20437 20702
26287 3556
14044 16144
19756 28193
2804 1010
17...

output:

29972

result:

ok single line: '29972'

Test #6:

score: 0
Accepted
time: 152ms
memory: 14916kb

input:

30000 448836
4333 21012
14460 183
3407 29071
19979 24057
23440 12679
22726 5093
18058 16105
15819 7077
1536 23098
2410 23719
17396 22428
21522 29071
21021 18668
12378 16100
17689 19507
24255 10320
28454 22428
13879 27181
8655 12679
20663 16100
20670 23098
17800 7077
6850 19507
14258 24057
658 7476
1...

output:

29972

result:

ok single line: '29972'

Test #7:

score: 0
Accepted
time: 151ms
memory: 15112kb

input:

30000 450781
10425 14609
4712 25859
4746 14609
7289 5259
4650 17712
4582 9326
16546 13846
24488 17712
27707 20805
15740 5856
26904 14255
7596 29395
26999 6790
10815 24642
12542 13846
10290 27885
7922 14255
6004 25859
12132 17712
18000 14255
19323 5259
29932 5247
3273 27885
27078 20805
16827 5247
275...

output:

29972

result:

ok single line: '29972'

Test #8:

score: 0
Accepted
time: 150ms
memory: 14960kb

input:

30000 449381
26362 3564
12849 1851
13538 2180
16828 25259
11088 1851
26319 1804
1578 18533
4662 8965
23981 18533
25004 2090
17851 20707
19744 22702
1027 29749
20280 8965
22588 16201
14657 22702
16950 15918
25703 29749
4297 1804
7797 17614
3173 25588
20407 1851
20925 16201
13894 13698
28559 17530
337...

output:

29972

result:

ok single line: '29972'

Test #9:

score: 0
Accepted
time: 153ms
memory: 14864kb

input:

30000 435758
19333 4266
17204 19615
23214 27677
13985 17138
25946 17138
16050 25784
18291 25265
11473 6207
6622 27278
19498 24605
2119 2320
5613 25265
639 5500
4899 25265
14554 16251
16781 16109
20598 27677
25591 27278
29167 4571
21768 25265
757 4571
6218 25784
10798 22400
3257 6207
26835 15208
2218...

output:

29973

result:

ok single line: '29973'

Test #10:

score: 0
Accepted
time: 152ms
memory: 14720kb

input:

30000 434473
29316 20548
11357 16723
24595 15903
29449 17974
24831 16723
29495 17974
10854 21997
9283 13100
7509 17974
23175 21997
12639 27410
26476 7352
6229 8268
4327 21747
7393 9111
27373 7352
9015 27410
11844 21997
9153 15903
3261 27410
645 20161
5766 19917
18283 3086
5730 20161
25898 24408
8657...

output:

29973

result:

ok single line: '29973'

Test #11:

score: 0
Accepted
time: 150ms
memory: 14648kb

input:

30000 433552
23769 5804
8460 10895
10177 28282
24516 5804
2399 14306
2896 9423
4732 14306
29256 17928
16765 12330
2667 2706
9097 2281
24004 26030
12213 2706
23974 7599
23707 10895
731 7599
2879 22639
25132 14586
5912 10895
26928 3891
19180 17972
29935 10697
29366 21716
7079 10697
3508 17972
24271 27...

output:

29973

result:

ok single line: '29973'

Test #12:

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

input:

30000 194101
29208 3924
28953 3526
2926 23661
28908 28668
7500 25979
17745 12442
17931 23661
23892 21087
19866 12026
24160 7916
16592 12026
13031 3924
18212 28668
25017 25979
23826 28668
19203 3924
18291 12026
2459 7916
16231 25979
11553 3526
27426 21087
25469 17008
15214 7916
9491 17651
23667 12442...

output:

29989

result:

ok single line: '29989'

Test #13:

score: 0
Accepted
time: 61ms
memory: 10460kb

input:

30000 224602
10723 6633
28621 1462
25648 26308
25058 1462
7733 25014
8551 23591
29214 19636
11963 16657
22785 28301
27328 26308
10808 6633
9465 26308
2391 6633
20211 6452
5050 17444
9875 10367
17558 6452
11019 6633
6707 18076
11358 23591
17886 13906
20452 10367
11085 6633
2445 6633
7009 18076
5544 2...

output:

29987

result:

ok single line: '29987'

Test #14:

score: 0
Accepted
time: 83ms
memory: 10820kb

input:

30000 239634
17016 14893
21797 24610
9066 24610
7309 22817
16779 26282
24577 10631
9173 8632
2637 10631
10678 21462
5102 8632
16555 342
10111 13687
29824 8632
29674 342
11277 10631
25538 342
8952 8632
16069 13687
501 8555
19541 22817
27354 24610
11647 8555
4852 10631
25651 8632
4939 342
21022 10631
...

output:

29986

result:

ok single line: '29986'

Test #15:

score: 0
Accepted
time: 47ms
memory: 8456kb

input:

30000 150605
19224 29834
12097 6862
2546 28339
2084 18547
18603 26256
14257 29834
28372 6862
7054 19590
19979 28339
9259 18547
19602 6862
4369 19590
180 6862
2330 6862
12586 26256
11043 6862
6724 28339
5876 6862
2331 28339
28567 28339
29739 19590
12603 20763
12325 29834
10673 29834
5489 6862
3537 68...

output:

29992

result:

ok single line: '29992'

Test #16:

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

input:

30000 104560
8966 6237
27438 5730
22667 6237
3437 5730
13066 25206
29440 4975
2013 25206
3743 10730
939 10730
20237 25206
4615 4975
24241 6237
18005 25206
21835 25206
29599 10730
6731 25206
15477 25206
29781 6237
14851 10730
5372 6237
1429 5730
24760 4975
21612 25206
20862 25206
22684 25206
22155 49...

output:

29995

result:

ok single line: '29995'

Test #17:

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

input:

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

output:

-1

result:

ok single line: '-1'

Test #18:

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

input:

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

output:

-1

result:

ok single line: '-1'

Test #19:

score: 0
Accepted
time: 75ms
memory: 13260kb

input:

20000 388901
0 8631
0 18137
0 861
0 11174
0 16527
0 9727
1 10418
1 6932
1 16527
1 10868
1 18860
1 18137
1 13224
1 8631
1 19524
1 13119
1 10811
1 11174
1 16047
1 9772
1 8691
1 440
1 847
1 1402
1 15387
1 16134
1 861
1 19383
1 13645
1 2257
1 15904
1 4102
1 16742
1 19304
1 18669
1 13682
1 327
1 12700
1 ...

output:

-1

result:

ok single line: '-1'

Test #20:

score: 0
Accepted
time: 84ms
memory: 13596kb

input:

20000 397976
0 16863
0 7271
0 18514
0 13150
0 11405
0 1498
0 15159
0 7012
0 5763
0 8848
0 15400
0 13138
0 15467
0 4297
0 3368
0 5857
0 6814
0 10485
0 1409
0 2231
0 15766
0 15387
0 12657
0 2474
0 4250
0 18422
0 16138
0 11371
0 10495
0 16203
0 2567
1 3368
1 17614
1 7012
1 18514
1 13138
1 16138
1 18422...

output:

-1

result:

ok single line: '-1'

Test #21:

score: 0
Accepted
time: 53ms
memory: 13080kb

input:

10000 395291
0 284
0 6654
0 6829
0 7809
0 4412
0 3030
0 9705
0 5966
0 772
1 6095
1 1979
1 5935
1 6551
1 2475
1 5122
1 6019
1 1186
1 1730
1 3250
1 4350
1 8040
1 2741
1 6486
1 6654
1 2558
1 4564
1 5966
1 6608
1 7825
1 8821
1 219
1 1006
1 4291
1 165
1 9705
1 6390
1 7359
1 2624
1 2579
1 5830
1 3391
1 13...

output:

-1

result:

ok single line: '-1'

Test #22:

score: 0
Accepted
time: 71ms
memory: 12848kb

input:

15000 433562
0 13668
0 2721
0 14725
0 795
0 10928
0 7169
0 4483
0 3249
0 2691
0 247
0 3108
0 2775
0 3131
0 14146
0 6189
0 8397
0 14713
0 8154
0 4486
0 4146
0 7071
0 3971
0 14359
0 434
0 4944
0 11818
0 7936
0 7478
0 13256
0 5474
0 13296
0 2754
0 6015
0 13833
0 10425
0 8537
1 4146
1 3108
1 8154
1 1332...

output:

-1

result:

ok single line: '-1'

Test #23:

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

input:

2 1
0 1

output:

1

result:

ok single line: '1'

Test #24:

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

input:

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

output:

3

result:

ok single line: '3'

Test #25:

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

input:

30 110
20 16
20 2
24 25
9 27
4 17
29 1
29 3
9 18
15 3
8 11
24 23
29 0
5 6
8 14
29 27
4 27
29 18
24 17
8 0
8 10
20 14
4 21
4 2
19 23
19 11
4 0
24 14
26 0
15 12
8 17
24 28
8 3
4 18
29 23
4 11
9 6
5 7
9 10
24 2
15 11
9 25
19 27
9 1
9 23
20 22
24 27
8 12
5 22
15 17
15 7
29 28
8 7
20 25
26 7
8 27
8 21
24...

output:

20

result:

ok single line: '20'

Test #26:

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

input:

102 784
6 28
26 28
22 28
12 28
23 28
11 28
1 28
13 28
3 28
27 28
25 28
17 28
16 28
0 28
15 28
7 28
5 29
8 29
7 29
17 29
25 29
18 29
26 29
15 29
23 29
6 29
16 29
11 29
19 29
12 29
9 29
13 29
4 29
3 29
0 29
2 29
22 29
24 29
21 29
1 29
20 29
10 29
27 29
21 30
19 30
4 30
17 30
2 30
9 30
15 30
10 30
23 3...

output:

74

result:

ok single line: '74'

Test #27:

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

input:

80 625
11 25
6 25
16 25
19 25
4 25
21 25
5 25
20 25
14 25
10 25
0 25
8 25
8 26
19 26
24 26
17 26
12 26
16 26
2 26
13 26
21 26
0 26
4 26
22 26
5 26
11 26
7 26
20 26
6 26
15 26
1 26
3 26
21 27
8 27
1 27
17 27
16 27
23 27
24 27
19 27
3 27
15 27
11 27
20 27
7 27
9 27
13 27
6 27
14 27
18 27
2 27
12 27
5 ...

output:

55

result:

ok single line: '55'

Test #28:

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

input:

270 729
13 27
2 27
7 27
18 28
17 28
11 28
4 29
12 29
5 29
6 30
14 30
10 30
0 31
24 31
21 31
1 32
19 32
16 32
20 33
25 33
22 33
23 34
15 34
8 34
26 35
9 35
3 35
7 36
20 36
15 36
14 37
23 37
26 37
16 38
25 38
6 38
5 39
11 39
10 39
21 40
2 40
8 40
9 41
12 41
24 41
13 42
4 42
17 42
22 43
1 43
18 43
19 4...

output:

243

result:

ok single line: '243'

Test #29:

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

input:

97 729
7 27
20 27
10 27
9 27
13 27
21 27
23 27
16 27
2 27
8 27
24 28
20 28
6 28
2 28
4 28
9 28
19 28
21 28
0 28
18 28
7 28
0 29
22 29
15 29
16 29
12 29
14 29
25 29
3 29
1 29
11 29
18 29
7 29
7 30
15 30
3 30
6 30
26 30
18 30
22 30
25 30
11 30
8 30
9 30
24 30
0 30
5 30
10 30
16 30
19 30
4 30
17 30
23 ...

output:

70

result:

ok single line: '70'

Test #30:

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

input:

91 729
3 27
4 27
8 27
9 27
0 27
18 27
13 27
20 27
5 27
24 27
10 27
11 27
23 27
17 27
15 27
22 28
23 28
7 28
8 28
10 28
20 28
5 28
9 28
16 28
21 28
19 28
17 28
11 28
26 28
18 28
2 28
3 28
6 28
0 28
4 28
15 28
14 28
13 28
25 28
1 28
24 28
12 28
8 29
7 29
26 30
7 30
4 30
5 30
10 30
17 30
11 30
12 30
14...

output:

64

result:

ok single line: '64'

Test #31:

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

input:

70 441
14 21
1 21
7 21
5 21
2 21
10 21
20 22
5 23
2 23
13 23
10 23
19 23
1 23
18 23
20 23
8 23
14 23
4 23
12 23
6 23
9 23
7 23
17 23
11 23
0 23
16 23
5 24
15 24
16 24
4 24
17 24
20 24
11 24
14 24
12 24
19 24
7 24
15 25
12 25
17 25
13 25
14 25
4 25
20 25
0 25
10 25
5 25
16 25
2 25
19 25
11 25
0 26
12...

output:

49

result:

ok single line: '49'

Test #32:

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

input:

51 169
1 13
7 13
2 13
8 14
3 14
2 15
4 15
3 15
5 15
7 15
6 15
1 16
7 16
7 17
11 17
6 17
8 17
2 17
9 17
5 17
8 18
6 18
10 18
9 19
3 19
12 19
11 19
2 19
7 19
6 19
6 20
5 20
4 20
0 20
8 20
0 21
4 21
2 22
9 22
6 22
8 22
12 22
11 22
2 23
5 24
2 24
4 24
0 25
9 25
10 25
12 25
3 25
11 25
8 25
0 26
11 27
5 2...

output:

38

result:

ok single line: '38'

Test #33:

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

input:

230 4900
2 70
47 70
48 70
31 70
36 70
27 70
60 70
19 70
14 70
57 70
42 70
43 70
41 70
15 70
12 71
50 71
25 71
41 71
17 71
17 72
50 72
46 72
0 72
18 72
14 72
33 72
4 72
26 72
2 72
51 72
16 72
58 72
34 72
31 72
62 72
35 72
68 72
28 72
37 72
67 72
29 72
32 72
65 72
53 72
12 72
69 72
5 72
40 72
39 72
42...

output:

-1

result:

ok single line: '-1'

Test #34:

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

input:

99 841
6 29
2 29
20 29
0 29
3 29
17 29
21 29
28 29
19 29
4 29
7 29
24 29
12 29
13 30
17 30
6 30
8 30
4 30
19 30
25 30
27 30
1 30
26 30
7 30
3 30
9 30
20 30
12 31
27 31
26 31
2 31
13 31
17 31
28 31
19 31
5 31
24 31
25 31
15 31
8 31
20 31
18 31
22 31
7 31
21 31
14 31
9 31
3 31
1 31
23 31
11 31
0 31
1 ...

output:

-1

result:

ok single line: '-1'

Test #35:

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

input:

348 10404
6 102
82 102
5 102
20 102
0 102
41 102
71 102
64 102
56 102
14 103
12 103
95 103
84 103
73 103
59 103
87 103
96 103
27 103
54 103
91 103
0 103
99 103
23 103
47 103
57 103
41 103
79 103
62 103
13 103
31 103
72 103
66 103
21 103
40 103
6 103
30 103
35 104
7 104
42 104
86 104
84 104
96 104
9 ...

output:

-1

result:

ok single line: '-1'

Test #36:

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

input:

28 196
5 0
5 4
5 6
5 7
5 9
5 10
5 13
5 17
5 21
5 22
5 23
5 24
5 26
5 27
25 4
25 6
25 7
25 9
25 10
25 13
25 17
25 21
25 22
25 23
25 24
25 26
25 27
25 0
3 6
3 7
3 9
3 10
3 13
3 17
3 21
3 22
3 23
3 24
3 26
3 27
3 0
3 4
16 7
16 9
16 10
16 13
16 17
16 21
16 22
16 23
16 24
16 26
16 27
16 0
16 4
16 6
2 9
2...

output:

14

result:

ok single line: '14'

Test #37:

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

input:

40 400
34 2
34 3
34 5
34 6
34 8
34 9
34 10
34 11
34 12
34 13
34 15
34 20
34 21
34 22
34 23
34 24
34 30
34 32
34 37
34 39
38 3
38 5
38 6
38 8
38 9
38 10
38 11
38 12
38 13
38 15
38 20
38 21
38 22
38 23
38 24
38 30
38 32
38 37
38 39
38 2
19 5
19 6
19 8
19 9
19 10
19 11
19 12
19 13
19 15
19 20
19 21
19 ...

output:

20

result:

ok single line: '20'

Test #38:

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

input:

56 784
7 1
7 4
7 5
7 6
7 9
7 13
7 14
7 20
7 22
7 27
7 29
7 31
7 32
7 33
7 34
7 35
7 39
7 40
7 41
7 43
7 44
7 45
7 46
7 48
7 51
7 53
7 54
7 55
24 4
24 5
24 6
24 9
24 13
24 14
24 20
24 22
24 27
24 29
24 31
24 32
24 33
24 34
24 35
24 39
24 40
24 41
24 43
24 44
24 45
24 46
24 48
24 51
24 53
24 54
24 55
...

output:

28

result:

ok single line: '28'

Test #39:

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

input:

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

output:

6

result:

ok single line: '6'

Test #40:

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

input:

200 10000
6 2
6 3
6 4
6 11
6 14
6 17
6 18
6 19
6 20
6 22
6 23
6 28
6 33
6 35
6 36
6 38
6 42
6 43
6 45
6 46
6 52
6 53
6 61
6 63
6 64
6 67
6 68
6 69
6 70
6 73
6 74
6 75
6 76
6 78
6 82
6 83
6 84
6 85
6 89
6 90
6 92
6 94
6 95
6 98
6 100
6 102
6 103
6 104
6 105
6 106
6 110
6 113
6 114
6 115
6 116
6 118
6...

output:

-1

result:

ok single line: '-1'

Test #41:

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

input:

36 35
35 34
33 35
32 35
31 35
30 35
34 20
34 21
33 22
33 23
32 24
32 25
31 26
31 27
30 28
30 29
29 10
27 12
26 13
25 14
24 15
23 16
22 17
28 11
21 18
20 19
19 0
18 1
17 2
16 3
15 4
14 5
13 6
12 7
11 8
10 9

output:

21

result:

ok single line: '21'

Test #42:

score: 0
Accepted
time: 106ms
memory: 12556kb

input:

22222 332896
3185 18564
17554 8259
10368 5698
7852 12491
15565 17488
10024 17698
19365 8259
17975 9175
9010 17323
2314 21134
5705 10164
18947 19397
2454 12601
10352 3489
9763 12491
18733 805
853 10164
4331 12340
9621 18564
611 16777
19801 10164
4274 12491
13252 3762
20814 8263
20105 12491
16682 2113...

output:

22194

result:

ok single line: '22194'

Test #43:

score: 0
Accepted
time: 92ms
memory: 11296kb

input:

29999 255546
12519 1710
11291 28048
18990 4594
3817 2262
13642 28048
10197 24253
25706 1710
28045 1710
15690 24253
28153 1995
28896 1995
13649 26308
26251 22400
22712 19915
10690 1710
18568 92
22858 92
8566 22400
19142 1710
22492 24253
27678 9334
2231 4594
7952 1995
8440 1710
13695 28048
22616 2262
...

output:

29984

result:

ok single line: '29984'

Test #44:

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

input:

270 727
9 252
8 259
20 255
2 255
24 29
19 237
10 230
9 264
25 170
24 221
21 220
13 88
11 234
24 233
8 205
18 68
4 59
24 260
5 241
19 126
10 73
4 146
22 98
20 47
18 111
20 86
22 233
14 84
16 189
14 208
19 149
18 198
26 74
24 215
1 210
18 43
7 88
20 124
7 203
0 74
12 97
5 258
25 224
3 187
7 195
0 56
1...

output:

243

result:

ok single line: '243'

Test #45:

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

input:

126 322
11 100
8 59
14 104
11 30
0 119
10 123
0 110
8 105
17 59
14 112
7 77
8 38
10 64
3 42
15 61
3 80
5 72
11 93
17 25
11 50
4 48
5 49
11 117
0 67
6 52
13 31
10 22
7 63
3 88
14 117
12 56
12 19
8 91
4 83
1 73
15 24
8 97
3 40
7 93
8 85
12 26
3 30
15 93
16 13
1 125
6 21
9 107
8 23
2 41
2 115
1 102
0 1...

output:

108

result:

ok single line: '108'

Test #46:

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

input:

5 7
1 0
2 3
1 4
1 2
3 1
3 4
0 4

output:

2

result:

ok single line: '2'

Test #47:

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

input:

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

output:

3

result:

ok single line: '3'

Test #48:

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

input:

41 224
0 22
0 17
0 6
0 37
0 11
0 14
0 18
0 30
0 21
1 10
1 21
1 22
1 37
1 29
1 14
1 5
1 17
1 3
2 5
2 20
2 17
2 6
2 7
2 29
2 40
2 22
2 30
3 6
3 34
3 38
3 15
3 37
3 20
3 24
3 21
3 16
3 4
3 9
3 39
4 30
4 17
4 5
4 20
4 21
4 19
4 18
4 14
5 40
5 33
5 36
5 23
5 35
5 15
5 25
5 31
5 27
5 28
5 16
5 34
6 14
6 8...

output:

23

result:

ok single line: '23'

Test #49:

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

input:

317 2992
0 20
0 38
0 165
0 225
0 141
0 33
0 2
0 245
0 300
0 233
1 45
1 300
1 233
1 33
1 20
1 117
1 2
1 298
1 294
1 13
2 225
2 30
2 50
2 104
2 109
2 130
2 144
2 155
2 290
2 299
2 314
2 5
2 6
2 7
2 24
2 26
2 31
2 96
2 107
2 119
2 145
2 152
2 158
2 161
2 163
2 168
2 175
2 177
2 192
2 268
2 271
2 276
2 ...

output:

299

result:

ok single line: '299'

Test #50:

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

input:

500 5302
0 300
0 428
0 137
0 120
0 261
0 462
0 39
0 423
0 475
0 245
0 32
1 347
1 316
1 120
1 76
1 428
1 129
1 137
1 494
1 245
1 433
1 261
2 475
2 428
2 245
2 120
2 316
2 129
2 462
2 32
2 300
2 423
2 39
3 475
3 494
3 137
3 300
3 129
3 120
3 261
3 76
3 316
3 189
3 39
4 433
4 129
4 475
4 261
4 316
4 39...

output:

482

result:

ok single line: '482'

Test #51:

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

input:

43 202
0 36
0 27
0 9
0 8
0 31
0 10
0 22
1 10
1 9
1 28
1 39
1 40
1 22
1 38
2 18
2 27
2 38
2 28
2 39
2 36
2 4
3 38
3 8
3 27
3 31
3 7
3 28
3 9
4 40
4 13
4 32
4 42
4 11
4 19
4 34
4 12
4 14
4 21
4 30
4 35
5 22
5 10
5 39
5 23
5 38
5 36
5 8
6 22
6 27
6 18
6 38
6 9
6 40
6 7
7 31
7 12
7 14
7 28
7 24
7 26
7 2...

output:

28

result:

ok single line: '28'

Test #52:

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

input:

322 2472
0 35
0 319
0 170
0 268
0 113
0 133
0 215
0 130
1 316
1 113
1 302
1 75
1 12
1 35
1 133
1 130
2 130
2 302
2 75
2 35
2 12
2 215
2 170
2 113
3 215
3 268
3 12
3 133
3 35
3 302
3 44
3 113
4 35
4 302
4 316
4 12
4 44
4 215
4 268
4 130
5 316
5 75
5 35
5 44
5 130
5 133
5 302
5 113
6 316
6 113
6 133
6...

output:

309

result:

ok single line: '309'

Test #53:

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

input:

499 4350
0 163
0 190
0 4
0 18
0 228
0 166
0 86
0 7
0 463
1 228
1 62
1 163
1 287
1 346
1 166
1 4
1 386
1 371
2 287
2 346
2 446
2 228
2 386
2 166
2 18
2 163
2 4
3 463
3 7
3 371
3 166
3 86
3 287
3 446
3 4
3 18
4 371
4 5
4 32
4 33
4 56
4 64
4 68
4 76
4 80
4 83
4 104
4 128
4 199
4 210
4 276
4 303
4 315
4...

output:

483

result:

ok single line: '483'

Test #54:

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

input:

425 2090
0 12
0 290
0 317
0 409
0 129
1 213
1 129
1 409
1 290
1 12
2 290
2 317
2 409
2 213
2 129
3 255
3 317
3 129
3 290
3 213
4 317
4 409
4 290
4 129
4 213
5 213
5 255
5 290
5 129
5 317
6 409
6 213
6 317
6 129
6 255
7 409
7 255
7 290
7 213
7 12
8 255
8 409
8 290
8 213
8 129
9 213
9 129
9 255
9 12
9...

output:

418

result:

ok single line: '418'

Test #55:

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

input:

228 1105
0 171
0 174
0 116
0 107
0 68
1 174
1 171
1 65
1 107
1 169
2 171
2 107
2 116
2 174
2 68
3 65
3 107
3 174
3 171
3 169
4 65
4 107
4 68
4 174
4 116
5 169
5 116
5 174
5 68
5 107
6 65
6 169
6 107
6 174
6 68
7 65
7 169
7 107
7 171
7 68
8 68
8 169
8 171
8 116
8 65
9 65
9 171
9 116
9 107
9 68
10 116...

output:

221

result:

ok single line: '221'

Test #56:

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

input:

415 824
0 41
0 203
1 41
1 203
2 156
2 41
3 203
3 41
4 156
4 203
5 203
5 41
6 156
6 41
7 203
7 41
8 203
8 41
9 156
9 41
10 41
10 156
11 203
11 41
12 156
12 41
13 203
13 41
14 41
14 156
15 156
15 41
16 156
16 41
17 203
17 41
18 203
18 156
19 41
19 203
20 203
20 41
21 41
21 156
22 203
22 156
23 203
23 ...

output:

412

result:

ok single line: '412'

Test #57:

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

input:

40 107
0 14
0 7
0 9
1 14
1 9
1 12
1 13
1 15
1 16
1 26
1 29
1 34
1 3
1 5
1 8
1 11
1 18
1 25
1 31
1 4
1 10
1 20
1 23
1 27
1 28
1 30
1 33
1 36
1 38
2 14
2 24
2 7
3 14
3 24
4 14
4 9
5 7
5 9
6 7
6 14
6 24
7 8
7 17
7 18
7 19
7 27
7 30
7 32
7 12
7 20
7 33
7 15
7 16
7 21
7 25
7 26
7 29
7 31
7 35
7 37
8 14
9...

output:

35

result:

ok single line: '35'

Test #58:

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

input:

46 164
0 9
0 24
0 30
0 29
1 19
1 9
1 24
1 30
2 24
2 29
2 30
2 19
3 29
3 30
3 19
3 9
4 30
4 9
4 29
4 19
5 30
5 29
5 9
5 19
6 30
6 9
6 19
6 24
7 9
7 19
7 24
7 30
8 30
8 24
8 9
8 19
9 14
9 20
9 25
9 27
9 31
9 33
9 39
9 45
9 18
9 28
9 35
9 36
9 40
9 43
9 10
9 12
9 34
9 37
9 44
9 15
9 16
9 17
9 21
9 22
9...

output:

41

result:

ok single line: '41'

Test #59:

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

input:

217 1045
0 13
0 178
0 42
0 68
0 60
1 42
1 142
1 15
1 60
1 13
2 53
2 68
2 13
2 178
2 42
3 142
3 42
3 15
3 68
3 178
4 68
4 42
4 60
4 142
4 15
5 13
5 53
5 60
5 142
5 42
6 13
6 42
6 178
6 68
6 60
7 15
7 142
7 178
7 68
7 60
8 42
8 53
8 60
8 178
8 13
9 42
9 178
9 13
9 142
9 15
10 142
10 42
10 68
10 60
10 ...

output:

209

result:

ok single line: '209'

Test #60:

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

input:

36 35
35 34
33 35
32 35
31 35
30 35
34 20
34 21
33 22
33 23
32 24
32 25
31 26
31 27
30 28
30 29
29 10
27 12
26 13
25 14
24 15
23 16
22 17
28 11
21 18
20 19
19 0
18 1
17 2
16 3
15 4
14 5
13 6
12 7
11 8
10 9

output:

21

result:

ok single line: '21'

Test #61:

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

input:

30 156
0 8
0 4
0 15
0 16
0 26
0 9
0 6
0 12
0 22
0 24
0 13
0 17
0 21
0 23
1 2
1 27
1 8
1 14
1 10
1 26
1 19
1 20
1 18
2 11
2 19
2 17
2 21
2 12
2 13
2 22
2 15
2 3
2 6
3 7
3 10
3 26
3 27
3 20
3 19
3 25
3 18
4 18
4 28
4 5
4 6
4 11
4 24
4 19
4 9
4 27
4 10
4 16
5 20
5 14
5 19
5 8
5 29
5 18
5 28
5 25
6 18
6...

output:

15

result:

ok single line: '15'

Test #62:

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

input:

400 9200
76 0
269 0
62 0
304 0
237 0
99 0
219 0
334 0
54 0
340 0
114 0
166 0
267 0
209 0
301 0
324 0
391 0
335 0
159 0
271 0
92 0
326 0
3 0
183 0
319 0
180 0
19 0
126 0
200 0
182 0
300 0
190 0
98 0
336 0
270 0
386 0
212 0
170 0
184 0
217 0
157 0
359 0
96 0
70 1
284 1
162 1
267 1
176 1
316 1
218 1
8 ...

output:

-1

result:

ok single line: '-1'

Test #63:

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

input:

400 9147
104 0
243 0
232 0
119 0
90 0
221 0
185 0
201 0
214 0
312 0
292 0
362 0
68 0
298 0
27 0
54 0
205 0
100 0
43 0
5 0
365 0
13 0
39 0
122 0
381 0
250 0
161 0
203 0
391 0
101 0
86 0
171 0
284 0
283 0
76 0
266 0
125 0
174 0
367 0
158 0
382 0
285 0
173 0
157 0
57 0
106 0
109 0
289 0
215 0
126 0
202...

output:

-1

result:

ok single line: '-1'

Test #64:

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

input:

400 7942
5 0
129 0
352 0
201 0
241 0
320 0
72 0
103 0
101 0
319 0
152 0
11 0
217 0
161 0
185 0
247 0
253 0
190 0
61 0
124 0
186 0
398 0
218 0
298 0
133 0
92 0
68 0
365 0
159 0
3 0
49 0
308 0
66 0
37 0
282 0
120 0
203 0
83 0
384 0
310 0
338 0
393 0
145 0
30 0
172 0
226 0
346 1
192 1
154 1
304 1
321 1...

output:

-1

result:

ok single line: '-1'

Test #65:

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

input:

400 8602
338 0
345 0
279 0
318 0
348 0
180 0
26 0
152 0
76 0
6 0
92 0
264 0
336 0
367 0
181 0
395 0
20 0
368 0
103 0
47 0
310 0
280 0
158 0
237 0
330 0
374 0
337 0
283 0
109 0
191 0
151 0
15 0
333 0
39 0
244 0
77 0
255 0
198 0
64 0
354 0
79 0
117 0
108 0
13 0
53 0
245 0
382 0
195 1
375 1
129 1
22 1
...

output:

-1

result:

ok single line: '-1'

Test #66:

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

input:

400 8488
222 0
179 0
250 0
285 0
311 0
68 0
111 0
345 0
358 0
354 0
308 0
365 0
83 0
164 0
254 0
8 0
75 0
370 0
215 0
153 0
262 0
73 0
209 0
18 0
16 0
160 0
34 0
381 0
185 0
241 0
110 0
39 0
82 0
33 0
40 0
276 0
11 0
72 0
332 0
252 0
77 0
339 0
341 0
43 1
287 1
369 1
134 1
337 1
182 1
176 1
271 1
5 ...

output:

-1

result:

ok single line: '-1'

Test #67:

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

input:

400 9600
306 0
30 0
288 0
256 0
178 0
328 0
223 0
219 0
179 0
375 0
32 0
184 0
384 0
100 0
85 0
3 0
216 0
50 0
209 0
60 0
34 0
253 0
74 0
317 0
120 0
35 0
316 0
69 0
353 0
356 0
159 0
177 0
363 0
362 0
83 0
20 0
300 0
259 0
366 0
195 0
274 0
95 0
156 0
212 0
248 0
395 0
27 0
386 1
119 1
79 1
343 1
8...

output:

-1

result:

ok single line: '-1'

Test #68:

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

input:

40 460
5 0
26 0
31 0
14 0
15 0
20 0
30 0
10 0
36 0
18 0
35 0
11 0
8 0
3 0
7 0
28 0
29 0
33 0
1 0
32 0
13 0
17 0
4 0
34 0
24 0
27 0
19 0
36 1
26 1
20 1
12 1
9 1
22 1
32 1
35 1
10 1
4 1
23 1
8 1
29 1
2 1
16 1
21 1
7 1
39 1
11 1
28 1
18 1
3 1
30 1
5 1
17 1
6 1
15 1
27 1
31 1
38 1
25 2
23 2
38 2
31 2
19...

output:

-1

result:

ok single line: '-1'

Test #69:

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

input:

40 460
9 0
24 0
31 0
36 0
17 0
8 0
25 0
19 0
28 0
21 0
18 0
6 0
26 0
3 0
13 0
23 0
10 0
30 0
29 0
27 1
4 1
38 1
15 1
6 1
19 1
23 1
11 1
21 1
14 1
2 1
17 1
35 1
16 1
5 1
12 1
10 1
29 1
32 1
31 1
22 1
20 1
39 1
3 1
18 1
33 1
34 1
25 1
8 1
33 2
35 2
9 2
38 2
6 2
5 2
26 2
29 2
23 2
19 2
36 2
14 2
11 2
3...

output:

-1

result:

ok single line: '-1'

Test #70:

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

input:

40 458
15 0
33 0
2 0
8 0
19 0
29 0
25 0
26 0
4 0
37 0
17 0
9 0
24 0
38 0
16 0
21 0
36 0
12 0
10 0
20 0
35 1
5 1
15 1
13 1
29 1
14 1
17 1
25 1
33 1
23 1
32 1
38 1
7 1
26 1
18 1
20 1
19 1
22 1
31 1
9 1
24 1
37 1
8 1
11 1
10 1
2 1
27 2
30 2
38 2
12 2
3 2
13 2
11 2
19 2
6 2
22 2
7 2
39 2
5 2
37 2
23 2
9...

output:

-1

result:

ok single line: '-1'

Test #71:

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

input:

39 349
23 0
11 0
20 0
2 0
29 0
17 0
13 0
9 0
36 0
35 0
3 0
33 0
12 0
27 0
34 0
8 0
21 0
34 1
2 1
23 1
35 1
17 1
24 1
15 1
11 1
28 1
22 1
38 1
27 1
19 1
37 1
25 1
18 1
16 1
32 1
30 1
20 1
36 1
14 1
38 2
9 2
6 2
26 2
29 2
18 2
22 2
35 2
33 3
17 3
32 3
29 3
4 3
12 3
38 3
30 3
7 3
36 3
31 3
34 3
20 3
18...

output:

-1

result:

ok single line: '-1'