#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];
namespace DSU {
vector<pii> ntedg;
int dsu[nmax];
void init(int n) {
for(int i = 0; i < n; i++)
dsu[i] = i;
}
int f(int x) { return dsu[x] == x? x : dsu[x] = f(dsu[x]); }
void unite(int x, int y) {
pii F = pii{x, y};
x = f(x);
y = f(y);
if(x == y) return;
ntedg.emplace_back(F);
dsu[x] = y;
}
}
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<tii> 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(S[reidx[a]] + S[reidx[b]], reidx[a], reidx[b]);
}
sort(all(edg));
DSU::init(n);
for(auto [C, x, y] : edg)
DSU::unite(x, y);
vector<pii> ntedg = move(DSU::ntedg);
ll sum = 0;
for(auto [a, b] : ntedg)
sum += S[a] + S[b];
cout << sum - accumulate(all(S), 0LL) + (*max_element(all(S))) << '\n';
}
/**
Anul asta nu se da centroid
-- Rugaciunile mele
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8024 KB |
Output is correct |
2 |
Correct |
71 ms |
34044 KB |
Output is correct |
3 |
Correct |
72 ms |
36200 KB |
Output is correct |
4 |
Correct |
81 ms |
34300 KB |
Output is correct |
5 |
Correct |
85 ms |
34040 KB |
Output is correct |
6 |
Correct |
80 ms |
34044 KB |
Output is correct |
7 |
Correct |
81 ms |
33916 KB |
Output is correct |
8 |
Correct |
2 ms |
8024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8024 KB |
Output is correct |
2 |
Correct |
71 ms |
34044 KB |
Output is correct |
3 |
Correct |
72 ms |
36200 KB |
Output is correct |
4 |
Correct |
81 ms |
34300 KB |
Output is correct |
5 |
Correct |
85 ms |
34040 KB |
Output is correct |
6 |
Correct |
80 ms |
34044 KB |
Output is correct |
7 |
Correct |
81 ms |
33916 KB |
Output is correct |
8 |
Correct |
2 ms |
8024 KB |
Output is correct |
9 |
Correct |
2 ms |
8028 KB |
Output is correct |
10 |
Correct |
122 ms |
35616 KB |
Output is correct |
11 |
Correct |
79 ms |
35768 KB |
Output is correct |
12 |
Correct |
72 ms |
35832 KB |
Output is correct |
13 |
Correct |
75 ms |
37116 KB |
Output is correct |
14 |
Correct |
137 ms |
36632 KB |
Output is correct |
15 |
Correct |
120 ms |
36856 KB |
Output is correct |
16 |
Correct |
132 ms |
35588 KB |
Output is correct |
17 |
Correct |
126 ms |
35576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8024 KB |
Output is correct |
2 |
Correct |
71 ms |
34044 KB |
Output is correct |
3 |
Correct |
72 ms |
36200 KB |
Output is correct |
4 |
Correct |
81 ms |
34300 KB |
Output is correct |
5 |
Correct |
85 ms |
34040 KB |
Output is correct |
6 |
Correct |
80 ms |
34044 KB |
Output is correct |
7 |
Correct |
81 ms |
33916 KB |
Output is correct |
8 |
Correct |
2 ms |
8024 KB |
Output is correct |
9 |
Correct |
2 ms |
8028 KB |
Output is correct |
10 |
Correct |
122 ms |
35616 KB |
Output is correct |
11 |
Correct |
79 ms |
35768 KB |
Output is correct |
12 |
Correct |
72 ms |
35832 KB |
Output is correct |
13 |
Correct |
75 ms |
37116 KB |
Output is correct |
14 |
Correct |
137 ms |
36632 KB |
Output is correct |
15 |
Correct |
120 ms |
36856 KB |
Output is correct |
16 |
Correct |
132 ms |
35588 KB |
Output is correct |
17 |
Correct |
126 ms |
35576 KB |
Output is correct |
18 |
Correct |
2 ms |
8028 KB |
Output is correct |
19 |
Correct |
171 ms |
37916 KB |
Output is correct |
20 |
Correct |
149 ms |
36636 KB |
Output is correct |
21 |
Correct |
171 ms |
38424 KB |
Output is correct |
22 |
Correct |
151 ms |
38904 KB |
Output is correct |
23 |
Correct |
148 ms |
38648 KB |
Output is correct |
24 |
Correct |
134 ms |
38992 KB |
Output is correct |
25 |
Correct |
130 ms |
37136 KB |
Output is correct |
26 |
Correct |
129 ms |
37624 KB |
Output is correct |
27 |
Correct |
148 ms |
37776 KB |
Output is correct |
28 |
Correct |
149 ms |
37912 KB |
Output is correct |
29 |
Correct |
156 ms |
36344 KB |
Output is correct |
30 |
Correct |
137 ms |
37008 KB |
Output is correct |
31 |
Correct |
126 ms |
38376 KB |
Output is correct |
32 |
Correct |
162 ms |
39020 KB |
Output is correct |
33 |
Correct |
135 ms |
37112 KB |
Output is correct |
34 |
Correct |
132 ms |
37112 KB |
Output is correct |
35 |
Correct |
153 ms |
37824 KB |
Output is correct |
36 |
Correct |
120 ms |
38700 KB |
Output is correct |
37 |
Correct |
126 ms |
39416 KB |
Output is correct |
38 |
Correct |
159 ms |
37112 KB |
Output is correct |
39 |
Correct |
126 ms |
38148 KB |
Output is correct |
40 |
Correct |
144 ms |
37976 KB |
Output is correct |
41 |
Correct |
154 ms |
34804 KB |
Output is correct |
42 |
Correct |
146 ms |
36852 KB |
Output is correct |
43 |
Correct |
147 ms |
36712 KB |
Output is correct |
44 |
Correct |
165 ms |
36852 KB |
Output is correct |
45 |
Correct |
165 ms |
36784 KB |
Output is correct |
46 |
Correct |
150 ms |
37364 KB |
Output is correct |
47 |
Correct |
172 ms |
37112 KB |
Output is correct |
48 |
Correct |
159 ms |
37624 KB |
Output is correct |
49 |
Correct |
150 ms |
36632 KB |
Output is correct |
50 |
Correct |
174 ms |
38104 KB |
Output is correct |
51 |
Correct |
125 ms |
36860 KB |
Output is correct |
52 |
Correct |
120 ms |
35364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8024 KB |
Output is correct |
2 |
Correct |
71 ms |
34044 KB |
Output is correct |
3 |
Correct |
72 ms |
36200 KB |
Output is correct |
4 |
Correct |
81 ms |
34300 KB |
Output is correct |
5 |
Correct |
85 ms |
34040 KB |
Output is correct |
6 |
Correct |
80 ms |
34044 KB |
Output is correct |
7 |
Correct |
81 ms |
33916 KB |
Output is correct |
8 |
Correct |
2 ms |
8024 KB |
Output is correct |
9 |
Correct |
2 ms |
8028 KB |
Output is correct |
10 |
Correct |
122 ms |
35616 KB |
Output is correct |
11 |
Correct |
79 ms |
35768 KB |
Output is correct |
12 |
Correct |
72 ms |
35832 KB |
Output is correct |
13 |
Correct |
75 ms |
37116 KB |
Output is correct |
14 |
Correct |
137 ms |
36632 KB |
Output is correct |
15 |
Correct |
120 ms |
36856 KB |
Output is correct |
16 |
Correct |
132 ms |
35588 KB |
Output is correct |
17 |
Correct |
126 ms |
35576 KB |
Output is correct |
18 |
Correct |
2 ms |
8028 KB |
Output is correct |
19 |
Correct |
171 ms |
37916 KB |
Output is correct |
20 |
Correct |
149 ms |
36636 KB |
Output is correct |
21 |
Correct |
171 ms |
38424 KB |
Output is correct |
22 |
Correct |
151 ms |
38904 KB |
Output is correct |
23 |
Correct |
148 ms |
38648 KB |
Output is correct |
24 |
Correct |
134 ms |
38992 KB |
Output is correct |
25 |
Correct |
130 ms |
37136 KB |
Output is correct |
26 |
Correct |
129 ms |
37624 KB |
Output is correct |
27 |
Correct |
148 ms |
37776 KB |
Output is correct |
28 |
Correct |
149 ms |
37912 KB |
Output is correct |
29 |
Correct |
156 ms |
36344 KB |
Output is correct |
30 |
Correct |
137 ms |
37008 KB |
Output is correct |
31 |
Correct |
126 ms |
38376 KB |
Output is correct |
32 |
Correct |
162 ms |
39020 KB |
Output is correct |
33 |
Correct |
135 ms |
37112 KB |
Output is correct |
34 |
Correct |
132 ms |
37112 KB |
Output is correct |
35 |
Correct |
153 ms |
37824 KB |
Output is correct |
36 |
Correct |
120 ms |
38700 KB |
Output is correct |
37 |
Correct |
126 ms |
39416 KB |
Output is correct |
38 |
Correct |
159 ms |
37112 KB |
Output is correct |
39 |
Correct |
126 ms |
38148 KB |
Output is correct |
40 |
Correct |
144 ms |
37976 KB |
Output is correct |
41 |
Correct |
154 ms |
34804 KB |
Output is correct |
42 |
Correct |
146 ms |
36852 KB |
Output is correct |
43 |
Correct |
147 ms |
36712 KB |
Output is correct |
44 |
Correct |
165 ms |
36852 KB |
Output is correct |
45 |
Correct |
165 ms |
36784 KB |
Output is correct |
46 |
Correct |
150 ms |
37364 KB |
Output is correct |
47 |
Correct |
172 ms |
37112 KB |
Output is correct |
48 |
Correct |
159 ms |
37624 KB |
Output is correct |
49 |
Correct |
150 ms |
36632 KB |
Output is correct |
50 |
Correct |
174 ms |
38104 KB |
Output is correct |
51 |
Correct |
125 ms |
36860 KB |
Output is correct |
52 |
Correct |
120 ms |
35364 KB |
Output is correct |
53 |
Correct |
2 ms |
8028 KB |
Output is correct |
54 |
Correct |
229 ms |
38676 KB |
Output is correct |
55 |
Correct |
181 ms |
37156 KB |
Output is correct |
56 |
Correct |
234 ms |
42988 KB |
Output is correct |
57 |
Correct |
268 ms |
50440 KB |
Output is correct |
58 |
Correct |
235 ms |
50432 KB |
Output is correct |
59 |
Correct |
271 ms |
49808 KB |
Output is correct |
60 |
Correct |
195 ms |
42772 KB |
Output is correct |
61 |
Correct |
256 ms |
49652 KB |
Output is correct |
62 |
Correct |
233 ms |
49648 KB |
Output is correct |
63 |
Correct |
162 ms |
36644 KB |
Output is correct |
64 |
Correct |
270 ms |
42060 KB |
Output is correct |
65 |
Correct |
255 ms |
48620 KB |
Output is correct |
66 |
Correct |
245 ms |
49136 KB |
Output is correct |
67 |
Correct |
251 ms |
49388 KB |
Output is correct |
68 |
Correct |
162 ms |
39160 KB |
Output is correct |
69 |
Correct |
269 ms |
46580 KB |
Output is correct |
70 |
Correct |
150 ms |
38904 KB |
Output is correct |
71 |
Correct |
124 ms |
40044 KB |
Output is correct |
72 |
Correct |
116 ms |
37884 KB |
Output is correct |
73 |
Correct |
148 ms |
38464 KB |
Output is correct |
74 |
Correct |
128 ms |
38648 KB |
Output is correct |
75 |
Correct |
131 ms |
36860 KB |
Output is correct |
76 |
Correct |
188 ms |
34812 KB |
Output is correct |
77 |
Correct |
143 ms |
36600 KB |
Output is correct |
78 |
Correct |
137 ms |
37628 KB |
Output is correct |
79 |
Correct |
295 ms |
50676 KB |
Output is correct |
80 |
Correct |
161 ms |
40028 KB |
Output is correct |
81 |
Correct |
251 ms |
47088 KB |
Output is correct |
82 |
Correct |
234 ms |
49644 KB |
Output is correct |
83 |
Correct |
265 ms |
50648 KB |
Output is correct |
84 |
Correct |
310 ms |
50172 KB |
Output is correct |
85 |
Correct |
173 ms |
38752 KB |
Output is correct |
86 |
Correct |
130 ms |
36860 KB |
Output is correct |
87 |
Correct |
126 ms |
36852 KB |
Output is correct |
88 |
Correct |
293 ms |
50472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8024 KB |
Output is correct |
2 |
Incorrect |
2 ms |
8028 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8024 KB |
Output is correct |
2 |
Incorrect |
2 ms |
8028 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8024 KB |
Output is correct |
2 |
Correct |
71 ms |
34044 KB |
Output is correct |
3 |
Correct |
72 ms |
36200 KB |
Output is correct |
4 |
Correct |
81 ms |
34300 KB |
Output is correct |
5 |
Correct |
85 ms |
34040 KB |
Output is correct |
6 |
Correct |
80 ms |
34044 KB |
Output is correct |
7 |
Correct |
81 ms |
33916 KB |
Output is correct |
8 |
Correct |
2 ms |
8024 KB |
Output is correct |
9 |
Correct |
2 ms |
8028 KB |
Output is correct |
10 |
Correct |
122 ms |
35616 KB |
Output is correct |
11 |
Correct |
79 ms |
35768 KB |
Output is correct |
12 |
Correct |
72 ms |
35832 KB |
Output is correct |
13 |
Correct |
75 ms |
37116 KB |
Output is correct |
14 |
Correct |
137 ms |
36632 KB |
Output is correct |
15 |
Correct |
120 ms |
36856 KB |
Output is correct |
16 |
Correct |
132 ms |
35588 KB |
Output is correct |
17 |
Correct |
126 ms |
35576 KB |
Output is correct |
18 |
Correct |
2 ms |
8028 KB |
Output is correct |
19 |
Correct |
171 ms |
37916 KB |
Output is correct |
20 |
Correct |
149 ms |
36636 KB |
Output is correct |
21 |
Correct |
171 ms |
38424 KB |
Output is correct |
22 |
Correct |
151 ms |
38904 KB |
Output is correct |
23 |
Correct |
148 ms |
38648 KB |
Output is correct |
24 |
Correct |
134 ms |
38992 KB |
Output is correct |
25 |
Correct |
130 ms |
37136 KB |
Output is correct |
26 |
Correct |
129 ms |
37624 KB |
Output is correct |
27 |
Correct |
148 ms |
37776 KB |
Output is correct |
28 |
Correct |
149 ms |
37912 KB |
Output is correct |
29 |
Correct |
156 ms |
36344 KB |
Output is correct |
30 |
Correct |
137 ms |
37008 KB |
Output is correct |
31 |
Correct |
126 ms |
38376 KB |
Output is correct |
32 |
Correct |
162 ms |
39020 KB |
Output is correct |
33 |
Correct |
135 ms |
37112 KB |
Output is correct |
34 |
Correct |
132 ms |
37112 KB |
Output is correct |
35 |
Correct |
153 ms |
37824 KB |
Output is correct |
36 |
Correct |
120 ms |
38700 KB |
Output is correct |
37 |
Correct |
126 ms |
39416 KB |
Output is correct |
38 |
Correct |
159 ms |
37112 KB |
Output is correct |
39 |
Correct |
126 ms |
38148 KB |
Output is correct |
40 |
Correct |
144 ms |
37976 KB |
Output is correct |
41 |
Correct |
154 ms |
34804 KB |
Output is correct |
42 |
Correct |
146 ms |
36852 KB |
Output is correct |
43 |
Correct |
147 ms |
36712 KB |
Output is correct |
44 |
Correct |
165 ms |
36852 KB |
Output is correct |
45 |
Correct |
165 ms |
36784 KB |
Output is correct |
46 |
Correct |
150 ms |
37364 KB |
Output is correct |
47 |
Correct |
172 ms |
37112 KB |
Output is correct |
48 |
Correct |
159 ms |
37624 KB |
Output is correct |
49 |
Correct |
150 ms |
36632 KB |
Output is correct |
50 |
Correct |
174 ms |
38104 KB |
Output is correct |
51 |
Correct |
125 ms |
36860 KB |
Output is correct |
52 |
Correct |
120 ms |
35364 KB |
Output is correct |
53 |
Correct |
2 ms |
8028 KB |
Output is correct |
54 |
Correct |
229 ms |
38676 KB |
Output is correct |
55 |
Correct |
181 ms |
37156 KB |
Output is correct |
56 |
Correct |
234 ms |
42988 KB |
Output is correct |
57 |
Correct |
268 ms |
50440 KB |
Output is correct |
58 |
Correct |
235 ms |
50432 KB |
Output is correct |
59 |
Correct |
271 ms |
49808 KB |
Output is correct |
60 |
Correct |
195 ms |
42772 KB |
Output is correct |
61 |
Correct |
256 ms |
49652 KB |
Output is correct |
62 |
Correct |
233 ms |
49648 KB |
Output is correct |
63 |
Correct |
162 ms |
36644 KB |
Output is correct |
64 |
Correct |
270 ms |
42060 KB |
Output is correct |
65 |
Correct |
255 ms |
48620 KB |
Output is correct |
66 |
Correct |
245 ms |
49136 KB |
Output is correct |
67 |
Correct |
251 ms |
49388 KB |
Output is correct |
68 |
Correct |
162 ms |
39160 KB |
Output is correct |
69 |
Correct |
269 ms |
46580 KB |
Output is correct |
70 |
Correct |
150 ms |
38904 KB |
Output is correct |
71 |
Correct |
124 ms |
40044 KB |
Output is correct |
72 |
Correct |
116 ms |
37884 KB |
Output is correct |
73 |
Correct |
148 ms |
38464 KB |
Output is correct |
74 |
Correct |
128 ms |
38648 KB |
Output is correct |
75 |
Correct |
131 ms |
36860 KB |
Output is correct |
76 |
Correct |
188 ms |
34812 KB |
Output is correct |
77 |
Correct |
143 ms |
36600 KB |
Output is correct |
78 |
Correct |
137 ms |
37628 KB |
Output is correct |
79 |
Correct |
295 ms |
50676 KB |
Output is correct |
80 |
Correct |
161 ms |
40028 KB |
Output is correct |
81 |
Correct |
251 ms |
47088 KB |
Output is correct |
82 |
Correct |
234 ms |
49644 KB |
Output is correct |
83 |
Correct |
265 ms |
50648 KB |
Output is correct |
84 |
Correct |
310 ms |
50172 KB |
Output is correct |
85 |
Correct |
173 ms |
38752 KB |
Output is correct |
86 |
Correct |
130 ms |
36860 KB |
Output is correct |
87 |
Correct |
126 ms |
36852 KB |
Output is correct |
88 |
Correct |
293 ms |
50472 KB |
Output is correct |
89 |
Correct |
2 ms |
8024 KB |
Output is correct |
90 |
Incorrect |
2 ms |
8028 KB |
Output isn't correct |
91 |
Halted |
0 ms |
0 KB |
- |