#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using ld = long double;
//#define int ll
#define sz(x) ((int)(x).size())
using pii = pair<int,int>;
using tii = tuple<int,int,int>;
const int nmax = 2e5 + 5;
vector<int> S;
vector<int> g[nmax];
int occ[nmax];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int n, m, q;
cin >> n >> m >> q;
S.resize(n);
for(auto &x : S) cin >> x;
vector<int> dir_ord(n), reidx(n + 1);
iota(all(dir_ord), 0);
sort(all(dir_ord), [&](int a, int b) { return S[a] < S[b]; });
sort(all(S));
for(int i = 0; i < n; i++)
reidx[dir_ord[i] + 1] = i;
//for(auto x : reidx) cerr << x << ' '; cerr << '\n';
vector<pii> edg;
for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
g[reidx[a]].emplace_back(reidx[b]);
g[reidx[b]].emplace_back(reidx[a]);
edg.emplace_back(reidx[a], reidx[b]);
}
for(int i = 0; i < n; i++)
sort(all(g[i]), greater<int>());
occ[0] = 1;
priority_queue<int, vector<int>, greater<int>> heap;
heap.emplace(0);
vector<pii> ntedg;
//exit(0);
while(!heap.empty()) {
int node = heap.top();
heap.pop();
//cerr << node << '\n';
while(!g[node].empty() && occ[g[node].back()] == 1) g[node].pop_back();
if(g[node].empty()) continue;
ntedg.emplace_back(node, g[node].back());
heap.emplace(g[node].back());
occ[g[node].back()] = 1;
g[node].pop_back();
if(!g[node].empty())
heap.emplace(node);
}
//exit(0);
ll sum = 0;
for(auto [a, b] : ntedg)
sum += S[a] + S[b];
//exit(0);
cout << sum - accumulate(all(S), 0LL) + (*max_element(all(S))) << '\n';
}
/**
Anul asta nu se da centroid
-- Rugaciunile mele
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5764 KB |
Output is correct |
2 |
Correct |
79 ms |
22068 KB |
Output is correct |
3 |
Correct |
84 ms |
21964 KB |
Output is correct |
4 |
Correct |
91 ms |
22056 KB |
Output is correct |
5 |
Correct |
78 ms |
21868 KB |
Output is correct |
6 |
Correct |
87 ms |
21876 KB |
Output is correct |
7 |
Correct |
84 ms |
21880 KB |
Output is correct |
8 |
Correct |
1 ms |
5768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5764 KB |
Output is correct |
2 |
Correct |
79 ms |
22068 KB |
Output is correct |
3 |
Correct |
84 ms |
21964 KB |
Output is correct |
4 |
Correct |
91 ms |
22056 KB |
Output is correct |
5 |
Correct |
78 ms |
21868 KB |
Output is correct |
6 |
Correct |
87 ms |
21876 KB |
Output is correct |
7 |
Correct |
84 ms |
21880 KB |
Output is correct |
8 |
Correct |
1 ms |
5768 KB |
Output is correct |
9 |
Correct |
2 ms |
5760 KB |
Output is correct |
10 |
Correct |
148 ms |
23432 KB |
Output is correct |
11 |
Correct |
90 ms |
23760 KB |
Output is correct |
12 |
Correct |
88 ms |
23552 KB |
Output is correct |
13 |
Correct |
74 ms |
23608 KB |
Output is correct |
14 |
Correct |
141 ms |
23636 KB |
Output is correct |
15 |
Correct |
127 ms |
23436 KB |
Output is correct |
16 |
Correct |
128 ms |
23500 KB |
Output is correct |
17 |
Correct |
122 ms |
23528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5764 KB |
Output is correct |
2 |
Correct |
79 ms |
22068 KB |
Output is correct |
3 |
Correct |
84 ms |
21964 KB |
Output is correct |
4 |
Correct |
91 ms |
22056 KB |
Output is correct |
5 |
Correct |
78 ms |
21868 KB |
Output is correct |
6 |
Correct |
87 ms |
21876 KB |
Output is correct |
7 |
Correct |
84 ms |
21880 KB |
Output is correct |
8 |
Correct |
1 ms |
5768 KB |
Output is correct |
9 |
Correct |
2 ms |
5760 KB |
Output is correct |
10 |
Correct |
148 ms |
23432 KB |
Output is correct |
11 |
Correct |
90 ms |
23760 KB |
Output is correct |
12 |
Correct |
88 ms |
23552 KB |
Output is correct |
13 |
Correct |
74 ms |
23608 KB |
Output is correct |
14 |
Correct |
141 ms |
23636 KB |
Output is correct |
15 |
Correct |
127 ms |
23436 KB |
Output is correct |
16 |
Correct |
128 ms |
23500 KB |
Output is correct |
17 |
Correct |
122 ms |
23528 KB |
Output is correct |
18 |
Correct |
2 ms |
5768 KB |
Output is correct |
19 |
Correct |
219 ms |
23440 KB |
Output is correct |
20 |
Correct |
177 ms |
23416 KB |
Output is correct |
21 |
Correct |
182 ms |
23708 KB |
Output is correct |
22 |
Correct |
210 ms |
23712 KB |
Output is correct |
23 |
Correct |
174 ms |
24388 KB |
Output is correct |
24 |
Correct |
168 ms |
24980 KB |
Output is correct |
25 |
Correct |
173 ms |
25096 KB |
Output is correct |
26 |
Correct |
157 ms |
24732 KB |
Output is correct |
27 |
Correct |
141 ms |
24168 KB |
Output is correct |
28 |
Correct |
200 ms |
24224 KB |
Output is correct |
29 |
Correct |
180 ms |
24484 KB |
Output is correct |
30 |
Correct |
179 ms |
24736 KB |
Output is correct |
31 |
Correct |
139 ms |
24528 KB |
Output is correct |
32 |
Correct |
186 ms |
24492 KB |
Output is correct |
33 |
Correct |
176 ms |
22668 KB |
Output is correct |
34 |
Correct |
171 ms |
24228 KB |
Output is correct |
35 |
Correct |
191 ms |
25288 KB |
Output is correct |
36 |
Correct |
185 ms |
25364 KB |
Output is correct |
37 |
Correct |
123 ms |
25284 KB |
Output is correct |
38 |
Correct |
133 ms |
23716 KB |
Output is correct |
39 |
Correct |
146 ms |
24232 KB |
Output is correct |
40 |
Correct |
141 ms |
24260 KB |
Output is correct |
41 |
Correct |
130 ms |
22736 KB |
Output is correct |
42 |
Correct |
138 ms |
23456 KB |
Output is correct |
43 |
Correct |
119 ms |
24260 KB |
Output is correct |
44 |
Correct |
156 ms |
24224 KB |
Output is correct |
45 |
Correct |
198 ms |
24304 KB |
Output is correct |
46 |
Correct |
144 ms |
24420 KB |
Output is correct |
47 |
Correct |
142 ms |
23664 KB |
Output is correct |
48 |
Correct |
191 ms |
23708 KB |
Output is correct |
49 |
Correct |
135 ms |
24296 KB |
Output is correct |
50 |
Correct |
123 ms |
23712 KB |
Output is correct |
51 |
Correct |
175 ms |
24528 KB |
Output is correct |
52 |
Correct |
116 ms |
22724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5764 KB |
Output is correct |
2 |
Correct |
79 ms |
22068 KB |
Output is correct |
3 |
Correct |
84 ms |
21964 KB |
Output is correct |
4 |
Correct |
91 ms |
22056 KB |
Output is correct |
5 |
Correct |
78 ms |
21868 KB |
Output is correct |
6 |
Correct |
87 ms |
21876 KB |
Output is correct |
7 |
Correct |
84 ms |
21880 KB |
Output is correct |
8 |
Correct |
1 ms |
5768 KB |
Output is correct |
9 |
Correct |
2 ms |
5760 KB |
Output is correct |
10 |
Correct |
148 ms |
23432 KB |
Output is correct |
11 |
Correct |
90 ms |
23760 KB |
Output is correct |
12 |
Correct |
88 ms |
23552 KB |
Output is correct |
13 |
Correct |
74 ms |
23608 KB |
Output is correct |
14 |
Correct |
141 ms |
23636 KB |
Output is correct |
15 |
Correct |
127 ms |
23436 KB |
Output is correct |
16 |
Correct |
128 ms |
23500 KB |
Output is correct |
17 |
Correct |
122 ms |
23528 KB |
Output is correct |
18 |
Correct |
2 ms |
5768 KB |
Output is correct |
19 |
Correct |
219 ms |
23440 KB |
Output is correct |
20 |
Correct |
177 ms |
23416 KB |
Output is correct |
21 |
Correct |
182 ms |
23708 KB |
Output is correct |
22 |
Correct |
210 ms |
23712 KB |
Output is correct |
23 |
Correct |
174 ms |
24388 KB |
Output is correct |
24 |
Correct |
168 ms |
24980 KB |
Output is correct |
25 |
Correct |
173 ms |
25096 KB |
Output is correct |
26 |
Correct |
157 ms |
24732 KB |
Output is correct |
27 |
Correct |
141 ms |
24168 KB |
Output is correct |
28 |
Correct |
200 ms |
24224 KB |
Output is correct |
29 |
Correct |
180 ms |
24484 KB |
Output is correct |
30 |
Correct |
179 ms |
24736 KB |
Output is correct |
31 |
Correct |
139 ms |
24528 KB |
Output is correct |
32 |
Correct |
186 ms |
24492 KB |
Output is correct |
33 |
Correct |
176 ms |
22668 KB |
Output is correct |
34 |
Correct |
171 ms |
24228 KB |
Output is correct |
35 |
Correct |
191 ms |
25288 KB |
Output is correct |
36 |
Correct |
185 ms |
25364 KB |
Output is correct |
37 |
Correct |
123 ms |
25284 KB |
Output is correct |
38 |
Correct |
133 ms |
23716 KB |
Output is correct |
39 |
Correct |
146 ms |
24232 KB |
Output is correct |
40 |
Correct |
141 ms |
24260 KB |
Output is correct |
41 |
Correct |
130 ms |
22736 KB |
Output is correct |
42 |
Correct |
138 ms |
23456 KB |
Output is correct |
43 |
Correct |
119 ms |
24260 KB |
Output is correct |
44 |
Correct |
156 ms |
24224 KB |
Output is correct |
45 |
Correct |
198 ms |
24304 KB |
Output is correct |
46 |
Correct |
144 ms |
24420 KB |
Output is correct |
47 |
Correct |
142 ms |
23664 KB |
Output is correct |
48 |
Correct |
191 ms |
23708 KB |
Output is correct |
49 |
Correct |
135 ms |
24296 KB |
Output is correct |
50 |
Correct |
123 ms |
23712 KB |
Output is correct |
51 |
Correct |
175 ms |
24528 KB |
Output is correct |
52 |
Correct |
116 ms |
22724 KB |
Output is correct |
53 |
Correct |
1 ms |
5720 KB |
Output is correct |
54 |
Incorrect |
208 ms |
23696 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Incorrect |
1 ms |
5724 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Incorrect |
1 ms |
5724 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5764 KB |
Output is correct |
2 |
Correct |
79 ms |
22068 KB |
Output is correct |
3 |
Correct |
84 ms |
21964 KB |
Output is correct |
4 |
Correct |
91 ms |
22056 KB |
Output is correct |
5 |
Correct |
78 ms |
21868 KB |
Output is correct |
6 |
Correct |
87 ms |
21876 KB |
Output is correct |
7 |
Correct |
84 ms |
21880 KB |
Output is correct |
8 |
Correct |
1 ms |
5768 KB |
Output is correct |
9 |
Correct |
2 ms |
5760 KB |
Output is correct |
10 |
Correct |
148 ms |
23432 KB |
Output is correct |
11 |
Correct |
90 ms |
23760 KB |
Output is correct |
12 |
Correct |
88 ms |
23552 KB |
Output is correct |
13 |
Correct |
74 ms |
23608 KB |
Output is correct |
14 |
Correct |
141 ms |
23636 KB |
Output is correct |
15 |
Correct |
127 ms |
23436 KB |
Output is correct |
16 |
Correct |
128 ms |
23500 KB |
Output is correct |
17 |
Correct |
122 ms |
23528 KB |
Output is correct |
18 |
Correct |
2 ms |
5768 KB |
Output is correct |
19 |
Correct |
219 ms |
23440 KB |
Output is correct |
20 |
Correct |
177 ms |
23416 KB |
Output is correct |
21 |
Correct |
182 ms |
23708 KB |
Output is correct |
22 |
Correct |
210 ms |
23712 KB |
Output is correct |
23 |
Correct |
174 ms |
24388 KB |
Output is correct |
24 |
Correct |
168 ms |
24980 KB |
Output is correct |
25 |
Correct |
173 ms |
25096 KB |
Output is correct |
26 |
Correct |
157 ms |
24732 KB |
Output is correct |
27 |
Correct |
141 ms |
24168 KB |
Output is correct |
28 |
Correct |
200 ms |
24224 KB |
Output is correct |
29 |
Correct |
180 ms |
24484 KB |
Output is correct |
30 |
Correct |
179 ms |
24736 KB |
Output is correct |
31 |
Correct |
139 ms |
24528 KB |
Output is correct |
32 |
Correct |
186 ms |
24492 KB |
Output is correct |
33 |
Correct |
176 ms |
22668 KB |
Output is correct |
34 |
Correct |
171 ms |
24228 KB |
Output is correct |
35 |
Correct |
191 ms |
25288 KB |
Output is correct |
36 |
Correct |
185 ms |
25364 KB |
Output is correct |
37 |
Correct |
123 ms |
25284 KB |
Output is correct |
38 |
Correct |
133 ms |
23716 KB |
Output is correct |
39 |
Correct |
146 ms |
24232 KB |
Output is correct |
40 |
Correct |
141 ms |
24260 KB |
Output is correct |
41 |
Correct |
130 ms |
22736 KB |
Output is correct |
42 |
Correct |
138 ms |
23456 KB |
Output is correct |
43 |
Correct |
119 ms |
24260 KB |
Output is correct |
44 |
Correct |
156 ms |
24224 KB |
Output is correct |
45 |
Correct |
198 ms |
24304 KB |
Output is correct |
46 |
Correct |
144 ms |
24420 KB |
Output is correct |
47 |
Correct |
142 ms |
23664 KB |
Output is correct |
48 |
Correct |
191 ms |
23708 KB |
Output is correct |
49 |
Correct |
135 ms |
24296 KB |
Output is correct |
50 |
Correct |
123 ms |
23712 KB |
Output is correct |
51 |
Correct |
175 ms |
24528 KB |
Output is correct |
52 |
Correct |
116 ms |
22724 KB |
Output is correct |
53 |
Correct |
1 ms |
5720 KB |
Output is correct |
54 |
Incorrect |
208 ms |
23696 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |