QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#730475#2512. Quality MonitoringpenguinmanWA 149ms15148kbC++234.2kb2024-11-09 20:22:582024-11-09 20:22:59

Judging History

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

  • [2024-11-09 20:22:59]
  • 评测
  • 测评结果:WA
  • 用时:149ms
  • 内存:15148kb
  • [2024-11-09 20:22: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(-inf, 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 <= 1){
        return remain;
    }
    if(p.first == 2){
        vl cand;
        rep(_,remain*2){
            p = seg.calc(0, n);
            if(p.first <= 1) break;
            seg.update(p.second, make_pair(-inf, p.second));
            cand.eb(p.second);
        }
        p = seg.calc(0, n);
        if(p.first == 2){
            for(auto s: cand) seg.update(s, make_pair(cnt[s], s));
            return -inf;
        }
        vl visited;
        for(auto s: cand){
            if(used[s]) continue;
            queue<ll> que;
            que.push(s);
            while(!que.empty()){
                ll now = que.front(); que.pop();
                visited.eb(now);
                for(auto next: edge[now]){
                    if(used[next]) continue;
                    que.push(next);
                    used[next] = true;
                }
            }
            remain -= SZ(visited)/2;
        }
        for(auto s: visited) used[s] = false;
        for(auto s: cand) seg.update(s, make_pair(cnt[s], s));
        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-28+dfs(28);
    if(ans < n-28) ans = -1;
    cout << ans << endl;
}

詳細信息

Test #1:

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

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: 123ms
memory: 13704kb

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: 115ms
memory: 13560kb

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: 146ms
memory: 15088kb

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: 149ms
memory: 15148kb

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: 148ms
memory: 14980kb

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: 147ms
memory: 15000kb

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: 149ms
memory: 15016kb

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: 143ms
memory: 14668kb

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: 143ms
memory: 14668kb

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: 141ms
memory: 14884kb

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: 51ms
memory: 10036kb

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: 72ms
memory: 10512kb

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: 81ms
memory: 10884kb

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: 42ms
memory: 8640kb

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: 35ms
memory: 7820kb

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: 4ms
memory: 4564kb

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: 38ms
memory: 11300kb

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: 86ms
memory: 13384kb

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: 83ms
memory: 13424kb

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: 51ms
memory: 12972kb

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: 67ms
memory: 13064kb

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: -100
Wrong Answer
time: 0ms
memory: 3780kb

input:

2 1
0 1

output:

2

result:

wrong answer 1st lines differ - expected: '1', found: '2'