답안 #952511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952511 2024-03-24T07:24:52 Z ttamx Security Guard (JOI23_guard) C++17
100 / 100
504 ms 94980 KB
#include<bits/stdc++.h>

using namespace std;

const int N=2e5+5;

using ll = long long;
using T = tuple<ll,int,int>;
using U = tuple<ll,int,int,int>;

int n,m,q;
int s[N],deg[N];
int rt;
ll cur;
vector<T> edge;
priority_queue<T,vector<T>,greater<T>> comp[N];
priority_queue<U,vector<U>,greater<U>> pq;
bool good[N];
vector<ll> ans;

struct DSU{
    int p[N];
    void init(){
        for(int i=1;i<=n;i++)p[i]=i;
    }
    int fp(int u){
        return p[u]=u==p[u]?u:fp(p[u]);
    }
    bool uni(int u,int v){
        u=fp(u),v=fp(v);
        return u!=v?p[u]=v,true:false;
    }
}dsu;

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> m >> q;
    for(int i=1;i<=n;i++){
        cin >> s[i];
    }
    rt=min_element(s+1,s+n+1)-s;
    cur+=1LL*(n-2)*s[rt]+*max_element(s+1,s+n+1);
    for(int i=0;i<m;i++){
        int u,v;
        cin >> u >> v;
        edge.emplace_back(s[u]+s[v],u,v);
    }
    sort(edge.begin(),edge.end());
    dsu.init();
    for(auto [w,u,v]:edge)if(dsu.uni(u,v)){
        if(u==rt||v==rt)good[u]=good[v]=true;
        else{
            comp[u].emplace(w,u,v);
            comp[v].emplace(w,v,u);
        }
    }
    good[rt]=false;
    dsu.init();
    for(int i=1;i<=n;i++)if(!good[i]&&!comp[i].empty()){
        auto [w,u,v]=comp[i].top();
        pq.emplace(w-(s[rt]+s[u]),u,v,i);
    }
    ans.emplace_back(cur);
    while(!pq.empty()){
        auto [w,u,v,p]=pq.top();
        pq.pop();
        u=dsu.fp(u),v=dsu.fp(v);
        if(u==v||u!=p)continue;
        cur+=w;
        ans.emplace_back(cur);
        if(comp[u].size()>comp[v].size())swap(comp[u],comp[v]);
        dsu.p[u]=v;
        while(!comp[u].empty()){
            comp[v].emplace(comp[u].top());
            comp[u].pop();
        }
        if(good[v])continue;
        while(!comp[v].empty()){
            auto [c,a,b]=comp[v].top();
            if(dsu.fp(a)!=dsu.fp(b))break;
            comp[v].pop();
        }
        if(!comp[v].empty()){
            auto [c,a,b]=comp[v].top();
            pq.emplace(c-(s[rt]+s[v]),a,b,v);
        }
    }
    reverse(ans.begin(),ans.end());
    for(int i=0;i<=q;i++)cout << ans[min(i,(int)ans.size()-1)] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 128 ms 40892 KB Output is correct
3 Correct 94 ms 39020 KB Output is correct
4 Correct 171 ms 41464 KB Output is correct
5 Correct 187 ms 38964 KB Output is correct
6 Correct 177 ms 41348 KB Output is correct
7 Correct 204 ms 40420 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 128 ms 40892 KB Output is correct
3 Correct 94 ms 39020 KB Output is correct
4 Correct 171 ms 41464 KB Output is correct
5 Correct 187 ms 38964 KB Output is correct
6 Correct 177 ms 41348 KB Output is correct
7 Correct 204 ms 40420 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 317 ms 34792 KB Output is correct
11 Correct 99 ms 40636 KB Output is correct
12 Correct 109 ms 44556 KB Output is correct
13 Correct 101 ms 43732 KB Output is correct
14 Correct 282 ms 39372 KB Output is correct
15 Correct 315 ms 39920 KB Output is correct
16 Correct 284 ms 41308 KB Output is correct
17 Correct 281 ms 40524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 128 ms 40892 KB Output is correct
3 Correct 94 ms 39020 KB Output is correct
4 Correct 171 ms 41464 KB Output is correct
5 Correct 187 ms 38964 KB Output is correct
6 Correct 177 ms 41348 KB Output is correct
7 Correct 204 ms 40420 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 317 ms 34792 KB Output is correct
11 Correct 99 ms 40636 KB Output is correct
12 Correct 109 ms 44556 KB Output is correct
13 Correct 101 ms 43732 KB Output is correct
14 Correct 282 ms 39372 KB Output is correct
15 Correct 315 ms 39920 KB Output is correct
16 Correct 284 ms 41308 KB Output is correct
17 Correct 281 ms 40524 KB Output is correct
18 Correct 2 ms 8680 KB Output is correct
19 Correct 338 ms 42300 KB Output is correct
20 Correct 318 ms 42160 KB Output is correct
21 Correct 341 ms 40524 KB Output is correct
22 Correct 345 ms 40568 KB Output is correct
23 Correct 307 ms 42424 KB Output is correct
24 Correct 283 ms 45548 KB Output is correct
25 Correct 291 ms 45800 KB Output is correct
26 Correct 197 ms 50844 KB Output is correct
27 Correct 151 ms 39748 KB Output is correct
28 Correct 299 ms 40872 KB Output is correct
29 Correct 275 ms 42216 KB Output is correct
30 Correct 302 ms 40824 KB Output is correct
31 Correct 138 ms 40512 KB Output is correct
32 Correct 275 ms 42360 KB Output is correct
33 Correct 236 ms 38524 KB Output is correct
34 Correct 339 ms 87060 KB Output is correct
35 Correct 322 ms 85764 KB Output is correct
36 Correct 221 ms 66556 KB Output is correct
37 Correct 228 ms 62732 KB Output is correct
38 Correct 230 ms 38748 KB Output is correct
39 Correct 173 ms 46040 KB Output is correct
40 Correct 224 ms 41748 KB Output is correct
41 Correct 176 ms 45204 KB Output is correct
42 Correct 207 ms 38720 KB Output is correct
43 Correct 308 ms 42368 KB Output is correct
44 Correct 311 ms 42968 KB Output is correct
45 Correct 342 ms 40572 KB Output is correct
46 Correct 289 ms 40116 KB Output is correct
47 Correct 320 ms 40812 KB Output is correct
48 Correct 351 ms 40692 KB Output is correct
49 Correct 216 ms 50364 KB Output is correct
50 Correct 262 ms 38096 KB Output is correct
51 Correct 326 ms 40800 KB Output is correct
52 Correct 242 ms 40680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 128 ms 40892 KB Output is correct
3 Correct 94 ms 39020 KB Output is correct
4 Correct 171 ms 41464 KB Output is correct
5 Correct 187 ms 38964 KB Output is correct
6 Correct 177 ms 41348 KB Output is correct
7 Correct 204 ms 40420 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 317 ms 34792 KB Output is correct
11 Correct 99 ms 40636 KB Output is correct
12 Correct 109 ms 44556 KB Output is correct
13 Correct 101 ms 43732 KB Output is correct
14 Correct 282 ms 39372 KB Output is correct
15 Correct 315 ms 39920 KB Output is correct
16 Correct 284 ms 41308 KB Output is correct
17 Correct 281 ms 40524 KB Output is correct
18 Correct 2 ms 8680 KB Output is correct
19 Correct 338 ms 42300 KB Output is correct
20 Correct 318 ms 42160 KB Output is correct
21 Correct 341 ms 40524 KB Output is correct
22 Correct 345 ms 40568 KB Output is correct
23 Correct 307 ms 42424 KB Output is correct
24 Correct 283 ms 45548 KB Output is correct
25 Correct 291 ms 45800 KB Output is correct
26 Correct 197 ms 50844 KB Output is correct
27 Correct 151 ms 39748 KB Output is correct
28 Correct 299 ms 40872 KB Output is correct
29 Correct 275 ms 42216 KB Output is correct
30 Correct 302 ms 40824 KB Output is correct
31 Correct 138 ms 40512 KB Output is correct
32 Correct 275 ms 42360 KB Output is correct
33 Correct 236 ms 38524 KB Output is correct
34 Correct 339 ms 87060 KB Output is correct
35 Correct 322 ms 85764 KB Output is correct
36 Correct 221 ms 66556 KB Output is correct
37 Correct 228 ms 62732 KB Output is correct
38 Correct 230 ms 38748 KB Output is correct
39 Correct 173 ms 46040 KB Output is correct
40 Correct 224 ms 41748 KB Output is correct
41 Correct 176 ms 45204 KB Output is correct
42 Correct 207 ms 38720 KB Output is correct
43 Correct 308 ms 42368 KB Output is correct
44 Correct 311 ms 42968 KB Output is correct
45 Correct 342 ms 40572 KB Output is correct
46 Correct 289 ms 40116 KB Output is correct
47 Correct 320 ms 40812 KB Output is correct
48 Correct 351 ms 40692 KB Output is correct
49 Correct 216 ms 50364 KB Output is correct
50 Correct 262 ms 38096 KB Output is correct
51 Correct 326 ms 40800 KB Output is correct
52 Correct 242 ms 40680 KB Output is correct
53 Correct 2 ms 8540 KB Output is correct
54 Correct 304 ms 42428 KB Output is correct
55 Correct 332 ms 42872 KB Output is correct
56 Correct 307 ms 42824 KB Output is correct
57 Correct 400 ms 46212 KB Output is correct
58 Correct 350 ms 48948 KB Output is correct
59 Correct 331 ms 51492 KB Output is correct
60 Correct 230 ms 45912 KB Output is correct
61 Correct 351 ms 55108 KB Output is correct
62 Correct 197 ms 53720 KB Output is correct
63 Correct 344 ms 41684 KB Output is correct
64 Correct 288 ms 44208 KB Output is correct
65 Correct 279 ms 48056 KB Output is correct
66 Correct 200 ms 53356 KB Output is correct
67 Correct 335 ms 47548 KB Output is correct
68 Correct 278 ms 37420 KB Output is correct
69 Correct 420 ms 91648 KB Output is correct
70 Correct 328 ms 85128 KB Output is correct
71 Correct 223 ms 67540 KB Output is correct
72 Correct 202 ms 64376 KB Output is correct
73 Correct 309 ms 38340 KB Output is correct
74 Correct 171 ms 45752 KB Output is correct
75 Correct 239 ms 40132 KB Output is correct
76 Correct 179 ms 43184 KB Output is correct
77 Correct 220 ms 38056 KB Output is correct
78 Correct 329 ms 42252 KB Output is correct
79 Correct 438 ms 49120 KB Output is correct
80 Correct 349 ms 43676 KB Output is correct
81 Correct 346 ms 46940 KB Output is correct
82 Correct 385 ms 49508 KB Output is correct
83 Correct 362 ms 49816 KB Output is correct
84 Correct 300 ms 50408 KB Output is correct
85 Correct 303 ms 37984 KB Output is correct
86 Correct 291 ms 42420 KB Output is correct
87 Correct 272 ms 38916 KB Output is correct
88 Correct 426 ms 54792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8792 KB Output is correct
5 Correct 2 ms 8536 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 21 ms 10840 KB Output is correct
9 Correct 16 ms 10792 KB Output is correct
10 Correct 25 ms 10576 KB Output is correct
11 Correct 20 ms 10832 KB Output is correct
12 Correct 14 ms 10840 KB Output is correct
13 Correct 14 ms 10696 KB Output is correct
14 Correct 14 ms 10840 KB Output is correct
15 Correct 16 ms 10844 KB Output is correct
16 Correct 14 ms 10840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8792 KB Output is correct
5 Correct 2 ms 8536 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 21 ms 10840 KB Output is correct
9 Correct 16 ms 10792 KB Output is correct
10 Correct 25 ms 10576 KB Output is correct
11 Correct 20 ms 10832 KB Output is correct
12 Correct 14 ms 10840 KB Output is correct
13 Correct 14 ms 10696 KB Output is correct
14 Correct 14 ms 10840 KB Output is correct
15 Correct 16 ms 10844 KB Output is correct
16 Correct 14 ms 10840 KB Output is correct
17 Correct 27 ms 11736 KB Output is correct
18 Correct 21 ms 11996 KB Output is correct
19 Correct 34 ms 13156 KB Output is correct
20 Correct 51 ms 16832 KB Output is correct
21 Correct 60 ms 16684 KB Output is correct
22 Correct 48 ms 15548 KB Output is correct
23 Correct 101 ms 21452 KB Output is correct
24 Correct 93 ms 17124 KB Output is correct
25 Correct 20 ms 11356 KB Output is correct
26 Correct 61 ms 14808 KB Output is correct
27 Correct 30 ms 12240 KB Output is correct
28 Correct 23 ms 11240 KB Output is correct
29 Correct 22 ms 11344 KB Output is correct
30 Correct 19 ms 11168 KB Output is correct
31 Correct 14 ms 10120 KB Output is correct
32 Correct 19 ms 10024 KB Output is correct
33 Correct 19 ms 11332 KB Output is correct
34 Correct 21 ms 11688 KB Output is correct
35 Correct 38 ms 13764 KB Output is correct
36 Correct 93 ms 23048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 128 ms 40892 KB Output is correct
3 Correct 94 ms 39020 KB Output is correct
4 Correct 171 ms 41464 KB Output is correct
5 Correct 187 ms 38964 KB Output is correct
6 Correct 177 ms 41348 KB Output is correct
7 Correct 204 ms 40420 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 317 ms 34792 KB Output is correct
11 Correct 99 ms 40636 KB Output is correct
12 Correct 109 ms 44556 KB Output is correct
13 Correct 101 ms 43732 KB Output is correct
14 Correct 282 ms 39372 KB Output is correct
15 Correct 315 ms 39920 KB Output is correct
16 Correct 284 ms 41308 KB Output is correct
17 Correct 281 ms 40524 KB Output is correct
18 Correct 2 ms 8680 KB Output is correct
19 Correct 338 ms 42300 KB Output is correct
20 Correct 318 ms 42160 KB Output is correct
21 Correct 341 ms 40524 KB Output is correct
22 Correct 345 ms 40568 KB Output is correct
23 Correct 307 ms 42424 KB Output is correct
24 Correct 283 ms 45548 KB Output is correct
25 Correct 291 ms 45800 KB Output is correct
26 Correct 197 ms 50844 KB Output is correct
27 Correct 151 ms 39748 KB Output is correct
28 Correct 299 ms 40872 KB Output is correct
29 Correct 275 ms 42216 KB Output is correct
30 Correct 302 ms 40824 KB Output is correct
31 Correct 138 ms 40512 KB Output is correct
32 Correct 275 ms 42360 KB Output is correct
33 Correct 236 ms 38524 KB Output is correct
34 Correct 339 ms 87060 KB Output is correct
35 Correct 322 ms 85764 KB Output is correct
36 Correct 221 ms 66556 KB Output is correct
37 Correct 228 ms 62732 KB Output is correct
38 Correct 230 ms 38748 KB Output is correct
39 Correct 173 ms 46040 KB Output is correct
40 Correct 224 ms 41748 KB Output is correct
41 Correct 176 ms 45204 KB Output is correct
42 Correct 207 ms 38720 KB Output is correct
43 Correct 308 ms 42368 KB Output is correct
44 Correct 311 ms 42968 KB Output is correct
45 Correct 342 ms 40572 KB Output is correct
46 Correct 289 ms 40116 KB Output is correct
47 Correct 320 ms 40812 KB Output is correct
48 Correct 351 ms 40692 KB Output is correct
49 Correct 216 ms 50364 KB Output is correct
50 Correct 262 ms 38096 KB Output is correct
51 Correct 326 ms 40800 KB Output is correct
52 Correct 242 ms 40680 KB Output is correct
53 Correct 2 ms 8540 KB Output is correct
54 Correct 304 ms 42428 KB Output is correct
55 Correct 332 ms 42872 KB Output is correct
56 Correct 307 ms 42824 KB Output is correct
57 Correct 400 ms 46212 KB Output is correct
58 Correct 350 ms 48948 KB Output is correct
59 Correct 331 ms 51492 KB Output is correct
60 Correct 230 ms 45912 KB Output is correct
61 Correct 351 ms 55108 KB Output is correct
62 Correct 197 ms 53720 KB Output is correct
63 Correct 344 ms 41684 KB Output is correct
64 Correct 288 ms 44208 KB Output is correct
65 Correct 279 ms 48056 KB Output is correct
66 Correct 200 ms 53356 KB Output is correct
67 Correct 335 ms 47548 KB Output is correct
68 Correct 278 ms 37420 KB Output is correct
69 Correct 420 ms 91648 KB Output is correct
70 Correct 328 ms 85128 KB Output is correct
71 Correct 223 ms 67540 KB Output is correct
72 Correct 202 ms 64376 KB Output is correct
73 Correct 309 ms 38340 KB Output is correct
74 Correct 171 ms 45752 KB Output is correct
75 Correct 239 ms 40132 KB Output is correct
76 Correct 179 ms 43184 KB Output is correct
77 Correct 220 ms 38056 KB Output is correct
78 Correct 329 ms 42252 KB Output is correct
79 Correct 438 ms 49120 KB Output is correct
80 Correct 349 ms 43676 KB Output is correct
81 Correct 346 ms 46940 KB Output is correct
82 Correct 385 ms 49508 KB Output is correct
83 Correct 362 ms 49816 KB Output is correct
84 Correct 300 ms 50408 KB Output is correct
85 Correct 303 ms 37984 KB Output is correct
86 Correct 291 ms 42420 KB Output is correct
87 Correct 272 ms 38916 KB Output is correct
88 Correct 426 ms 54792 KB Output is correct
89 Correct 2 ms 8540 KB Output is correct
90 Correct 2 ms 8540 KB Output is correct
91 Correct 2 ms 8540 KB Output is correct
92 Correct 2 ms 8792 KB Output is correct
93 Correct 2 ms 8536 KB Output is correct
94 Correct 2 ms 8540 KB Output is correct
95 Correct 2 ms 8540 KB Output is correct
96 Correct 21 ms 10840 KB Output is correct
97 Correct 16 ms 10792 KB Output is correct
98 Correct 25 ms 10576 KB Output is correct
99 Correct 20 ms 10832 KB Output is correct
100 Correct 14 ms 10840 KB Output is correct
101 Correct 14 ms 10696 KB Output is correct
102 Correct 14 ms 10840 KB Output is correct
103 Correct 16 ms 10844 KB Output is correct
104 Correct 14 ms 10840 KB Output is correct
105 Correct 27 ms 11736 KB Output is correct
106 Correct 21 ms 11996 KB Output is correct
107 Correct 34 ms 13156 KB Output is correct
108 Correct 51 ms 16832 KB Output is correct
109 Correct 60 ms 16684 KB Output is correct
110 Correct 48 ms 15548 KB Output is correct
111 Correct 101 ms 21452 KB Output is correct
112 Correct 93 ms 17124 KB Output is correct
113 Correct 20 ms 11356 KB Output is correct
114 Correct 61 ms 14808 KB Output is correct
115 Correct 30 ms 12240 KB Output is correct
116 Correct 23 ms 11240 KB Output is correct
117 Correct 22 ms 11344 KB Output is correct
118 Correct 19 ms 11168 KB Output is correct
119 Correct 14 ms 10120 KB Output is correct
120 Correct 19 ms 10024 KB Output is correct
121 Correct 19 ms 11332 KB Output is correct
122 Correct 21 ms 11688 KB Output is correct
123 Correct 38 ms 13764 KB Output is correct
124 Correct 93 ms 23048 KB Output is correct
125 Correct 361 ms 45832 KB Output is correct
126 Correct 370 ms 43904 KB Output is correct
127 Correct 371 ms 45296 KB Output is correct
128 Correct 380 ms 49828 KB Output is correct
129 Correct 377 ms 50552 KB Output is correct
130 Correct 356 ms 54324 KB Output is correct
131 Correct 307 ms 53356 KB Output is correct
132 Correct 260 ms 58096 KB Output is correct
133 Correct 260 ms 52856 KB Output is correct
134 Correct 362 ms 44012 KB Output is correct
135 Correct 372 ms 46076 KB Output is correct
136 Correct 317 ms 52888 KB Output is correct
137 Correct 229 ms 53288 KB Output is correct
138 Correct 410 ms 53664 KB Output is correct
139 Correct 317 ms 40504 KB Output is correct
140 Correct 504 ms 94980 KB Output is correct
141 Correct 349 ms 86156 KB Output is correct
142 Correct 236 ms 70284 KB Output is correct
143 Correct 206 ms 64180 KB Output is correct
144 Correct 253 ms 41656 KB Output is correct
145 Correct 167 ms 45496 KB Output is correct
146 Correct 265 ms 42960 KB Output is correct
147 Correct 201 ms 45252 KB Output is correct
148 Correct 249 ms 42256 KB Output is correct
149 Correct 345 ms 43096 KB Output is correct
150 Correct 413 ms 49784 KB Output is correct
151 Correct 361 ms 45764 KB Output is correct
152 Correct 436 ms 50100 KB Output is correct
153 Correct 482 ms 51472 KB Output is correct
154 Correct 409 ms 49164 KB Output is correct
155 Correct 295 ms 60196 KB Output is correct
156 Correct 276 ms 40964 KB Output is correct
157 Correct 330 ms 44084 KB Output is correct
158 Correct 302 ms 42568 KB Output is correct
159 Correct 449 ms 59972 KB Output is correct