Submission #952515

# Submission time Handle Problem Language Result Execution time Memory
952515 2024-03-24T07:25:39 Z ttamx Security Guard (JOI23_guard) C++17
100 / 100
437 ms 86732 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,ans[N];
vector<T> edge;
priority_queue<T,vector<T>,greater<T>> comp[N];
priority_queue<U,vector<U>,greater<U>> pq;

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)){
        comp[u].emplace(w,u,v);
        comp[v].emplace(w,v,u);
    }
    dsu.init();
    for(int i=1;i<=n;i++)if(!comp[i].empty()){
        auto [w,u,v]=comp[i].top();
        pq.emplace(w-(s[rt]+s[u]),u,v,i);
    }
    int cnt=n-1;
    ans[cnt]=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[--cnt]=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();
        }
        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);
        }
    }
    for(int i=0;i<=q;i++)cout << ans[min(i,n-1)] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 131 ms 35904 KB Output is correct
3 Correct 128 ms 35760 KB Output is correct
4 Correct 178 ms 38004 KB Output is correct
5 Correct 169 ms 37944 KB Output is correct
6 Correct 178 ms 38408 KB Output is correct
7 Correct 172 ms 38036 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 131 ms 35904 KB Output is correct
3 Correct 128 ms 35760 KB Output is correct
4 Correct 178 ms 38004 KB Output is correct
5 Correct 169 ms 37944 KB Output is correct
6 Correct 178 ms 38408 KB Output is correct
7 Correct 172 ms 38036 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8536 KB Output is correct
10 Correct 294 ms 37916 KB Output is correct
11 Correct 134 ms 38128 KB Output is correct
12 Correct 153 ms 38536 KB Output is correct
13 Correct 150 ms 38112 KB Output is correct
14 Correct 307 ms 37848 KB Output is correct
15 Correct 311 ms 37560 KB Output is correct
16 Correct 370 ms 39040 KB Output is correct
17 Correct 285 ms 39772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 131 ms 35904 KB Output is correct
3 Correct 128 ms 35760 KB Output is correct
4 Correct 178 ms 38004 KB Output is correct
5 Correct 169 ms 37944 KB Output is correct
6 Correct 178 ms 38408 KB Output is correct
7 Correct 172 ms 38036 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8536 KB Output is correct
10 Correct 294 ms 37916 KB Output is correct
11 Correct 134 ms 38128 KB Output is correct
12 Correct 153 ms 38536 KB Output is correct
13 Correct 150 ms 38112 KB Output is correct
14 Correct 307 ms 37848 KB Output is correct
15 Correct 311 ms 37560 KB Output is correct
16 Correct 370 ms 39040 KB Output is correct
17 Correct 285 ms 39772 KB Output is correct
18 Correct 2 ms 8536 KB Output is correct
19 Correct 339 ms 38708 KB Output is correct
20 Correct 325 ms 41060 KB Output is correct
21 Correct 339 ms 39016 KB Output is correct
22 Correct 345 ms 38900 KB Output is correct
23 Correct 328 ms 39988 KB Output is correct
24 Correct 256 ms 42152 KB Output is correct
25 Correct 261 ms 42848 KB Output is correct
26 Correct 299 ms 44216 KB Output is correct
27 Correct 206 ms 38896 KB Output is correct
28 Correct 280 ms 38952 KB Output is correct
29 Correct 260 ms 38064 KB Output is correct
30 Correct 232 ms 42656 KB Output is correct
31 Correct 196 ms 40884 KB Output is correct
32 Correct 301 ms 41508 KB Output is correct
33 Correct 252 ms 37896 KB Output is correct
34 Correct 359 ms 81472 KB Output is correct
35 Correct 359 ms 83656 KB Output is correct
36 Correct 276 ms 67876 KB Output is correct
37 Correct 273 ms 66156 KB Output is correct
38 Correct 234 ms 38772 KB Output is correct
39 Correct 225 ms 37376 KB Output is correct
40 Correct 284 ms 37804 KB Output is correct
41 Correct 243 ms 37204 KB Output is correct
42 Correct 281 ms 37912 KB Output is correct
43 Correct 321 ms 38320 KB Output is correct
44 Correct 293 ms 39152 KB Output is correct
45 Correct 302 ms 39352 KB Output is correct
46 Correct 346 ms 40084 KB Output is correct
47 Correct 303 ms 40628 KB Output is correct
48 Correct 334 ms 41584 KB Output is correct
49 Correct 255 ms 37820 KB Output is correct
50 Correct 258 ms 38352 KB Output is correct
51 Correct 345 ms 40772 KB Output is correct
52 Correct 271 ms 39828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 131 ms 35904 KB Output is correct
3 Correct 128 ms 35760 KB Output is correct
4 Correct 178 ms 38004 KB Output is correct
5 Correct 169 ms 37944 KB Output is correct
6 Correct 178 ms 38408 KB Output is correct
7 Correct 172 ms 38036 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8536 KB Output is correct
10 Correct 294 ms 37916 KB Output is correct
11 Correct 134 ms 38128 KB Output is correct
12 Correct 153 ms 38536 KB Output is correct
13 Correct 150 ms 38112 KB Output is correct
14 Correct 307 ms 37848 KB Output is correct
15 Correct 311 ms 37560 KB Output is correct
16 Correct 370 ms 39040 KB Output is correct
17 Correct 285 ms 39772 KB Output is correct
18 Correct 2 ms 8536 KB Output is correct
19 Correct 339 ms 38708 KB Output is correct
20 Correct 325 ms 41060 KB Output is correct
21 Correct 339 ms 39016 KB Output is correct
22 Correct 345 ms 38900 KB Output is correct
23 Correct 328 ms 39988 KB Output is correct
24 Correct 256 ms 42152 KB Output is correct
25 Correct 261 ms 42848 KB Output is correct
26 Correct 299 ms 44216 KB Output is correct
27 Correct 206 ms 38896 KB Output is correct
28 Correct 280 ms 38952 KB Output is correct
29 Correct 260 ms 38064 KB Output is correct
30 Correct 232 ms 42656 KB Output is correct
31 Correct 196 ms 40884 KB Output is correct
32 Correct 301 ms 41508 KB Output is correct
33 Correct 252 ms 37896 KB Output is correct
34 Correct 359 ms 81472 KB Output is correct
35 Correct 359 ms 83656 KB Output is correct
36 Correct 276 ms 67876 KB Output is correct
37 Correct 273 ms 66156 KB Output is correct
38 Correct 234 ms 38772 KB Output is correct
39 Correct 225 ms 37376 KB Output is correct
40 Correct 284 ms 37804 KB Output is correct
41 Correct 243 ms 37204 KB Output is correct
42 Correct 281 ms 37912 KB Output is correct
43 Correct 321 ms 38320 KB Output is correct
44 Correct 293 ms 39152 KB Output is correct
45 Correct 302 ms 39352 KB Output is correct
46 Correct 346 ms 40084 KB Output is correct
47 Correct 303 ms 40628 KB Output is correct
48 Correct 334 ms 41584 KB Output is correct
49 Correct 255 ms 37820 KB Output is correct
50 Correct 258 ms 38352 KB Output is correct
51 Correct 345 ms 40772 KB Output is correct
52 Correct 271 ms 39828 KB Output is correct
53 Correct 2 ms 8540 KB Output is correct
54 Correct 289 ms 40804 KB Output is correct
55 Correct 321 ms 41652 KB Output is correct
56 Correct 303 ms 41768 KB Output is correct
57 Correct 354 ms 47776 KB Output is correct
58 Correct 310 ms 46156 KB Output is correct
59 Correct 309 ms 48568 KB Output is correct
60 Correct 247 ms 43180 KB Output is correct
61 Correct 270 ms 51288 KB Output is correct
62 Correct 266 ms 52144 KB Output is correct
63 Correct 298 ms 39348 KB Output is correct
64 Correct 313 ms 43552 KB Output is correct
65 Correct 321 ms 45208 KB Output is correct
66 Correct 292 ms 50644 KB Output is correct
67 Correct 329 ms 44920 KB Output is correct
68 Correct 247 ms 39552 KB Output is correct
69 Correct 398 ms 84660 KB Output is correct
70 Correct 408 ms 86732 KB Output is correct
71 Correct 289 ms 68184 KB Output is correct
72 Correct 272 ms 67972 KB Output is correct
73 Correct 239 ms 38860 KB Output is correct
74 Correct 206 ms 37576 KB Output is correct
75 Correct 219 ms 37052 KB Output is correct
76 Correct 203 ms 36272 KB Output is correct
77 Correct 213 ms 36460 KB Output is correct
78 Correct 310 ms 38708 KB Output is correct
79 Correct 366 ms 45388 KB Output is correct
80 Correct 300 ms 40372 KB Output is correct
81 Correct 356 ms 44316 KB Output is correct
82 Correct 357 ms 43944 KB Output is correct
83 Correct 347 ms 45636 KB Output is correct
84 Correct 307 ms 43444 KB Output is correct
85 Correct 230 ms 36080 KB Output is correct
86 Correct 320 ms 38264 KB Output is correct
87 Correct 268 ms 37300 KB Output is correct
88 Correct 391 ms 53076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 2 ms 8536 KB Output is correct
3 Correct 1 ms 8640 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 13 ms 10840 KB Output is correct
9 Correct 13 ms 11096 KB Output is correct
10 Correct 13 ms 10584 KB Output is correct
11 Correct 13 ms 10844 KB Output is correct
12 Correct 13 ms 10840 KB Output is correct
13 Correct 13 ms 10844 KB Output is correct
14 Correct 14 ms 10844 KB Output is correct
15 Correct 14 ms 10844 KB Output is correct
16 Correct 14 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 2 ms 8536 KB Output is correct
3 Correct 1 ms 8640 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 13 ms 10840 KB Output is correct
9 Correct 13 ms 11096 KB Output is correct
10 Correct 13 ms 10584 KB Output is correct
11 Correct 13 ms 10844 KB Output is correct
12 Correct 13 ms 10840 KB Output is correct
13 Correct 13 ms 10844 KB Output is correct
14 Correct 14 ms 10844 KB Output is correct
15 Correct 14 ms 10844 KB Output is correct
16 Correct 14 ms 10840 KB Output is correct
17 Correct 21 ms 11864 KB Output is correct
18 Correct 20 ms 11736 KB Output is correct
19 Correct 32 ms 13248 KB Output is correct
20 Correct 49 ms 15552 KB Output is correct
21 Correct 59 ms 16356 KB Output is correct
22 Correct 48 ms 16296 KB Output is correct
23 Correct 92 ms 21104 KB Output is correct
24 Correct 69 ms 16904 KB Output is correct
25 Correct 16 ms 11356 KB Output is correct
26 Correct 45 ms 14788 KB Output is correct
27 Correct 23 ms 12252 KB Output is correct
28 Correct 16 ms 11356 KB Output is correct
29 Correct 15 ms 11100 KB Output is correct
30 Correct 16 ms 11352 KB Output is correct
31 Correct 14 ms 10076 KB Output is correct
32 Correct 14 ms 10076 KB Output is correct
33 Correct 17 ms 11352 KB Output is correct
34 Correct 18 ms 11476 KB Output is correct
35 Correct 42 ms 13864 KB Output is correct
36 Correct 92 ms 20920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 131 ms 35904 KB Output is correct
3 Correct 128 ms 35760 KB Output is correct
4 Correct 178 ms 38004 KB Output is correct
5 Correct 169 ms 37944 KB Output is correct
6 Correct 178 ms 38408 KB Output is correct
7 Correct 172 ms 38036 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8536 KB Output is correct
10 Correct 294 ms 37916 KB Output is correct
11 Correct 134 ms 38128 KB Output is correct
12 Correct 153 ms 38536 KB Output is correct
13 Correct 150 ms 38112 KB Output is correct
14 Correct 307 ms 37848 KB Output is correct
15 Correct 311 ms 37560 KB Output is correct
16 Correct 370 ms 39040 KB Output is correct
17 Correct 285 ms 39772 KB Output is correct
18 Correct 2 ms 8536 KB Output is correct
19 Correct 339 ms 38708 KB Output is correct
20 Correct 325 ms 41060 KB Output is correct
21 Correct 339 ms 39016 KB Output is correct
22 Correct 345 ms 38900 KB Output is correct
23 Correct 328 ms 39988 KB Output is correct
24 Correct 256 ms 42152 KB Output is correct
25 Correct 261 ms 42848 KB Output is correct
26 Correct 299 ms 44216 KB Output is correct
27 Correct 206 ms 38896 KB Output is correct
28 Correct 280 ms 38952 KB Output is correct
29 Correct 260 ms 38064 KB Output is correct
30 Correct 232 ms 42656 KB Output is correct
31 Correct 196 ms 40884 KB Output is correct
32 Correct 301 ms 41508 KB Output is correct
33 Correct 252 ms 37896 KB Output is correct
34 Correct 359 ms 81472 KB Output is correct
35 Correct 359 ms 83656 KB Output is correct
36 Correct 276 ms 67876 KB Output is correct
37 Correct 273 ms 66156 KB Output is correct
38 Correct 234 ms 38772 KB Output is correct
39 Correct 225 ms 37376 KB Output is correct
40 Correct 284 ms 37804 KB Output is correct
41 Correct 243 ms 37204 KB Output is correct
42 Correct 281 ms 37912 KB Output is correct
43 Correct 321 ms 38320 KB Output is correct
44 Correct 293 ms 39152 KB Output is correct
45 Correct 302 ms 39352 KB Output is correct
46 Correct 346 ms 40084 KB Output is correct
47 Correct 303 ms 40628 KB Output is correct
48 Correct 334 ms 41584 KB Output is correct
49 Correct 255 ms 37820 KB Output is correct
50 Correct 258 ms 38352 KB Output is correct
51 Correct 345 ms 40772 KB Output is correct
52 Correct 271 ms 39828 KB Output is correct
53 Correct 2 ms 8540 KB Output is correct
54 Correct 289 ms 40804 KB Output is correct
55 Correct 321 ms 41652 KB Output is correct
56 Correct 303 ms 41768 KB Output is correct
57 Correct 354 ms 47776 KB Output is correct
58 Correct 310 ms 46156 KB Output is correct
59 Correct 309 ms 48568 KB Output is correct
60 Correct 247 ms 43180 KB Output is correct
61 Correct 270 ms 51288 KB Output is correct
62 Correct 266 ms 52144 KB Output is correct
63 Correct 298 ms 39348 KB Output is correct
64 Correct 313 ms 43552 KB Output is correct
65 Correct 321 ms 45208 KB Output is correct
66 Correct 292 ms 50644 KB Output is correct
67 Correct 329 ms 44920 KB Output is correct
68 Correct 247 ms 39552 KB Output is correct
69 Correct 398 ms 84660 KB Output is correct
70 Correct 408 ms 86732 KB Output is correct
71 Correct 289 ms 68184 KB Output is correct
72 Correct 272 ms 67972 KB Output is correct
73 Correct 239 ms 38860 KB Output is correct
74 Correct 206 ms 37576 KB Output is correct
75 Correct 219 ms 37052 KB Output is correct
76 Correct 203 ms 36272 KB Output is correct
77 Correct 213 ms 36460 KB Output is correct
78 Correct 310 ms 38708 KB Output is correct
79 Correct 366 ms 45388 KB Output is correct
80 Correct 300 ms 40372 KB Output is correct
81 Correct 356 ms 44316 KB Output is correct
82 Correct 357 ms 43944 KB Output is correct
83 Correct 347 ms 45636 KB Output is correct
84 Correct 307 ms 43444 KB Output is correct
85 Correct 230 ms 36080 KB Output is correct
86 Correct 320 ms 38264 KB Output is correct
87 Correct 268 ms 37300 KB Output is correct
88 Correct 391 ms 53076 KB Output is correct
89 Correct 2 ms 8536 KB Output is correct
90 Correct 2 ms 8536 KB Output is correct
91 Correct 1 ms 8640 KB Output is correct
92 Correct 2 ms 8540 KB Output is correct
93 Correct 2 ms 8540 KB Output is correct
94 Correct 2 ms 8540 KB Output is correct
95 Correct 2 ms 8540 KB Output is correct
96 Correct 13 ms 10840 KB Output is correct
97 Correct 13 ms 11096 KB Output is correct
98 Correct 13 ms 10584 KB Output is correct
99 Correct 13 ms 10844 KB Output is correct
100 Correct 13 ms 10840 KB Output is correct
101 Correct 13 ms 10844 KB Output is correct
102 Correct 14 ms 10844 KB Output is correct
103 Correct 14 ms 10844 KB Output is correct
104 Correct 14 ms 10840 KB Output is correct
105 Correct 21 ms 11864 KB Output is correct
106 Correct 20 ms 11736 KB Output is correct
107 Correct 32 ms 13248 KB Output is correct
108 Correct 49 ms 15552 KB Output is correct
109 Correct 59 ms 16356 KB Output is correct
110 Correct 48 ms 16296 KB Output is correct
111 Correct 92 ms 21104 KB Output is correct
112 Correct 69 ms 16904 KB Output is correct
113 Correct 16 ms 11356 KB Output is correct
114 Correct 45 ms 14788 KB Output is correct
115 Correct 23 ms 12252 KB Output is correct
116 Correct 16 ms 11356 KB Output is correct
117 Correct 15 ms 11100 KB Output is correct
118 Correct 16 ms 11352 KB Output is correct
119 Correct 14 ms 10076 KB Output is correct
120 Correct 14 ms 10076 KB Output is correct
121 Correct 17 ms 11352 KB Output is correct
122 Correct 18 ms 11476 KB Output is correct
123 Correct 42 ms 13864 KB Output is correct
124 Correct 92 ms 20920 KB Output is correct
125 Correct 377 ms 43124 KB Output is correct
126 Correct 302 ms 43124 KB Output is correct
127 Correct 315 ms 43104 KB Output is correct
128 Correct 352 ms 49592 KB Output is correct
129 Correct 309 ms 48292 KB Output is correct
130 Correct 318 ms 51364 KB Output is correct
131 Correct 323 ms 49664 KB Output is correct
132 Correct 286 ms 49936 KB Output is correct
133 Correct 273 ms 54928 KB Output is correct
134 Correct 295 ms 42484 KB Output is correct
135 Correct 300 ms 42964 KB Output is correct
136 Correct 294 ms 49592 KB Output is correct
137 Correct 288 ms 52244 KB Output is correct
138 Correct 367 ms 48820 KB Output is correct
139 Correct 254 ms 40100 KB Output is correct
140 Correct 437 ms 86672 KB Output is correct
141 Correct 376 ms 81944 KB Output is correct
142 Correct 286 ms 67436 KB Output is correct
143 Correct 274 ms 63600 KB Output is correct
144 Correct 246 ms 38320 KB Output is correct
145 Correct 219 ms 36276 KB Output is correct
146 Correct 256 ms 36208 KB Output is correct
147 Correct 219 ms 38728 KB Output is correct
148 Correct 220 ms 39252 KB Output is correct
149 Correct 354 ms 40652 KB Output is correct
150 Correct 392 ms 44956 KB Output is correct
151 Correct 343 ms 41196 KB Output is correct
152 Correct 361 ms 46588 KB Output is correct
153 Correct 362 ms 47032 KB Output is correct
154 Correct 421 ms 47040 KB Output is correct
155 Correct 318 ms 44984 KB Output is correct
156 Correct 306 ms 37576 KB Output is correct
157 Correct 302 ms 40172 KB Output is correct
158 Correct 297 ms 37964 KB Output is correct
159 Correct 419 ms 56740 KB Output is correct