#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define rep(x,start,end) for(int x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n,m,k;
int arr[200005];
vector<ii> edges;
int p[200005];
int par(int i){
if (p[i]==i) return i;
else return p[i]=par(p[i]);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
cin>>n>>m>>k;
rep(x,1,n+1) cin>>arr[x];
int ans=*max_element(arr+1,arr+n+1)-accumulate(arr+1,arr+n+1,0LL);
rep(x,0,m){
int a,b; cin>>a>>b;
edges.pub({a,b});
}
sort(all(edges),[](ii i,ii j){
return arr[i.fi]+arr[i.se]<arr[j.fi]+arr[j.se];
});
rep(x,1,n+1) p[x]=x;
for (auto [a,b]:edges){
int val=arr[a]+arr[b];
a=par(a),b=par(b);
if (a==b) continue;
ans+=val;
p[a]=b;
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
37 ms |
7620 KB |
Output is correct |
3 |
Correct |
37 ms |
9424 KB |
Output is correct |
4 |
Correct |
39 ms |
8644 KB |
Output is correct |
5 |
Correct |
40 ms |
8924 KB |
Output is correct |
6 |
Correct |
40 ms |
8912 KB |
Output is correct |
7 |
Correct |
40 ms |
7880 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
37 ms |
7620 KB |
Output is correct |
3 |
Correct |
37 ms |
9424 KB |
Output is correct |
4 |
Correct |
39 ms |
8644 KB |
Output is correct |
5 |
Correct |
40 ms |
8924 KB |
Output is correct |
6 |
Correct |
40 ms |
8912 KB |
Output is correct |
7 |
Correct |
40 ms |
7880 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
61 ms |
8908 KB |
Output is correct |
11 |
Correct |
46 ms |
9416 KB |
Output is correct |
12 |
Correct |
43 ms |
8904 KB |
Output is correct |
13 |
Correct |
47 ms |
8908 KB |
Output is correct |
14 |
Correct |
60 ms |
8136 KB |
Output is correct |
15 |
Correct |
62 ms |
9160 KB |
Output is correct |
16 |
Correct |
59 ms |
8396 KB |
Output is correct |
17 |
Correct |
61 ms |
9168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
37 ms |
7620 KB |
Output is correct |
3 |
Correct |
37 ms |
9424 KB |
Output is correct |
4 |
Correct |
39 ms |
8644 KB |
Output is correct |
5 |
Correct |
40 ms |
8924 KB |
Output is correct |
6 |
Correct |
40 ms |
8912 KB |
Output is correct |
7 |
Correct |
40 ms |
7880 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
61 ms |
8908 KB |
Output is correct |
11 |
Correct |
46 ms |
9416 KB |
Output is correct |
12 |
Correct |
43 ms |
8904 KB |
Output is correct |
13 |
Correct |
47 ms |
8908 KB |
Output is correct |
14 |
Correct |
60 ms |
8136 KB |
Output is correct |
15 |
Correct |
62 ms |
9160 KB |
Output is correct |
16 |
Correct |
59 ms |
8396 KB |
Output is correct |
17 |
Correct |
61 ms |
9168 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
68 ms |
8136 KB |
Output is correct |
20 |
Correct |
65 ms |
8392 KB |
Output is correct |
21 |
Correct |
67 ms |
7884 KB |
Output is correct |
22 |
Correct |
66 ms |
9416 KB |
Output is correct |
23 |
Correct |
65 ms |
9412 KB |
Output is correct |
24 |
Correct |
67 ms |
9416 KB |
Output is correct |
25 |
Correct |
64 ms |
8136 KB |
Output is correct |
26 |
Correct |
63 ms |
8392 KB |
Output is correct |
27 |
Correct |
61 ms |
8392 KB |
Output is correct |
28 |
Correct |
64 ms |
9160 KB |
Output is correct |
29 |
Correct |
66 ms |
9428 KB |
Output is correct |
30 |
Correct |
62 ms |
8916 KB |
Output is correct |
31 |
Correct |
66 ms |
8988 KB |
Output is correct |
32 |
Correct |
69 ms |
8580 KB |
Output is correct |
33 |
Correct |
47 ms |
8916 KB |
Output is correct |
34 |
Correct |
68 ms |
8648 KB |
Output is correct |
35 |
Correct |
60 ms |
9416 KB |
Output is correct |
36 |
Correct |
60 ms |
9160 KB |
Output is correct |
37 |
Correct |
51 ms |
9672 KB |
Output is correct |
38 |
Correct |
56 ms |
9156 KB |
Output is correct |
39 |
Correct |
57 ms |
8388 KB |
Output is correct |
40 |
Correct |
55 ms |
8396 KB |
Output is correct |
41 |
Correct |
61 ms |
9416 KB |
Output is correct |
42 |
Correct |
60 ms |
9416 KB |
Output is correct |
43 |
Correct |
55 ms |
9288 KB |
Output is correct |
44 |
Correct |
68 ms |
8140 KB |
Output is correct |
45 |
Correct |
56 ms |
9468 KB |
Output is correct |
46 |
Correct |
55 ms |
8092 KB |
Output is correct |
47 |
Correct |
57 ms |
7632 KB |
Output is correct |
48 |
Correct |
61 ms |
9092 KB |
Output is correct |
49 |
Correct |
65 ms |
8392 KB |
Output is correct |
50 |
Correct |
65 ms |
9160 KB |
Output is correct |
51 |
Correct |
52 ms |
9156 KB |
Output is correct |
52 |
Correct |
43 ms |
7888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
37 ms |
7620 KB |
Output is correct |
3 |
Correct |
37 ms |
9424 KB |
Output is correct |
4 |
Correct |
39 ms |
8644 KB |
Output is correct |
5 |
Correct |
40 ms |
8924 KB |
Output is correct |
6 |
Correct |
40 ms |
8912 KB |
Output is correct |
7 |
Correct |
40 ms |
7880 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
61 ms |
8908 KB |
Output is correct |
11 |
Correct |
46 ms |
9416 KB |
Output is correct |
12 |
Correct |
43 ms |
8904 KB |
Output is correct |
13 |
Correct |
47 ms |
8908 KB |
Output is correct |
14 |
Correct |
60 ms |
8136 KB |
Output is correct |
15 |
Correct |
62 ms |
9160 KB |
Output is correct |
16 |
Correct |
59 ms |
8396 KB |
Output is correct |
17 |
Correct |
61 ms |
9168 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
68 ms |
8136 KB |
Output is correct |
20 |
Correct |
65 ms |
8392 KB |
Output is correct |
21 |
Correct |
67 ms |
7884 KB |
Output is correct |
22 |
Correct |
66 ms |
9416 KB |
Output is correct |
23 |
Correct |
65 ms |
9412 KB |
Output is correct |
24 |
Correct |
67 ms |
9416 KB |
Output is correct |
25 |
Correct |
64 ms |
8136 KB |
Output is correct |
26 |
Correct |
63 ms |
8392 KB |
Output is correct |
27 |
Correct |
61 ms |
8392 KB |
Output is correct |
28 |
Correct |
64 ms |
9160 KB |
Output is correct |
29 |
Correct |
66 ms |
9428 KB |
Output is correct |
30 |
Correct |
62 ms |
8916 KB |
Output is correct |
31 |
Correct |
66 ms |
8988 KB |
Output is correct |
32 |
Correct |
69 ms |
8580 KB |
Output is correct |
33 |
Correct |
47 ms |
8916 KB |
Output is correct |
34 |
Correct |
68 ms |
8648 KB |
Output is correct |
35 |
Correct |
60 ms |
9416 KB |
Output is correct |
36 |
Correct |
60 ms |
9160 KB |
Output is correct |
37 |
Correct |
51 ms |
9672 KB |
Output is correct |
38 |
Correct |
56 ms |
9156 KB |
Output is correct |
39 |
Correct |
57 ms |
8388 KB |
Output is correct |
40 |
Correct |
55 ms |
8396 KB |
Output is correct |
41 |
Correct |
61 ms |
9416 KB |
Output is correct |
42 |
Correct |
60 ms |
9416 KB |
Output is correct |
43 |
Correct |
55 ms |
9288 KB |
Output is correct |
44 |
Correct |
68 ms |
8140 KB |
Output is correct |
45 |
Correct |
56 ms |
9468 KB |
Output is correct |
46 |
Correct |
55 ms |
8092 KB |
Output is correct |
47 |
Correct |
57 ms |
7632 KB |
Output is correct |
48 |
Correct |
61 ms |
9092 KB |
Output is correct |
49 |
Correct |
65 ms |
8392 KB |
Output is correct |
50 |
Correct |
65 ms |
9160 KB |
Output is correct |
51 |
Correct |
52 ms |
9156 KB |
Output is correct |
52 |
Correct |
43 ms |
7888 KB |
Output is correct |
53 |
Correct |
1 ms |
2392 KB |
Output is correct |
54 |
Correct |
69 ms |
7880 KB |
Output is correct |
55 |
Correct |
70 ms |
11720 KB |
Output is correct |
56 |
Correct |
83 ms |
17080 KB |
Output is correct |
57 |
Correct |
119 ms |
17348 KB |
Output is correct |
58 |
Correct |
119 ms |
18884 KB |
Output is correct |
59 |
Correct |
123 ms |
18560 KB |
Output is correct |
60 |
Correct |
91 ms |
18108 KB |
Output is correct |
61 |
Correct |
127 ms |
18620 KB |
Output is correct |
62 |
Correct |
118 ms |
18376 KB |
Output is correct |
63 |
Correct |
71 ms |
13256 KB |
Output is correct |
64 |
Correct |
91 ms |
17848 KB |
Output is correct |
65 |
Correct |
124 ms |
17600 KB |
Output is correct |
66 |
Correct |
118 ms |
17084 KB |
Output is correct |
67 |
Correct |
129 ms |
19100 KB |
Output is correct |
68 |
Correct |
50 ms |
12488 KB |
Output is correct |
69 |
Correct |
91 ms |
17212 KB |
Output is correct |
70 |
Correct |
73 ms |
13796 KB |
Output is correct |
71 |
Correct |
55 ms |
12744 KB |
Output is correct |
72 |
Correct |
54 ms |
13096 KB |
Output is correct |
73 |
Correct |
58 ms |
11192 KB |
Output is correct |
74 |
Correct |
57 ms |
12780 KB |
Output is correct |
75 |
Correct |
58 ms |
11100 KB |
Output is correct |
76 |
Correct |
67 ms |
11976 KB |
Output is correct |
77 |
Correct |
62 ms |
10712 KB |
Output is correct |
78 |
Correct |
58 ms |
12232 KB |
Output is correct |
79 |
Correct |
121 ms |
18368 KB |
Output is correct |
80 |
Correct |
68 ms |
12740 KB |
Output is correct |
81 |
Correct |
88 ms |
17344 KB |
Output is correct |
82 |
Correct |
106 ms |
18220 KB |
Output is correct |
83 |
Correct |
106 ms |
18376 KB |
Output is correct |
84 |
Correct |
124 ms |
17604 KB |
Output is correct |
85 |
Correct |
66 ms |
11976 KB |
Output is correct |
86 |
Correct |
55 ms |
11976 KB |
Output is correct |
87 |
Correct |
46 ms |
9928 KB |
Output is correct |
88 |
Correct |
130 ms |
17456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
37 ms |
7620 KB |
Output is correct |
3 |
Correct |
37 ms |
9424 KB |
Output is correct |
4 |
Correct |
39 ms |
8644 KB |
Output is correct |
5 |
Correct |
40 ms |
8924 KB |
Output is correct |
6 |
Correct |
40 ms |
8912 KB |
Output is correct |
7 |
Correct |
40 ms |
7880 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
61 ms |
8908 KB |
Output is correct |
11 |
Correct |
46 ms |
9416 KB |
Output is correct |
12 |
Correct |
43 ms |
8904 KB |
Output is correct |
13 |
Correct |
47 ms |
8908 KB |
Output is correct |
14 |
Correct |
60 ms |
8136 KB |
Output is correct |
15 |
Correct |
62 ms |
9160 KB |
Output is correct |
16 |
Correct |
59 ms |
8396 KB |
Output is correct |
17 |
Correct |
61 ms |
9168 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
68 ms |
8136 KB |
Output is correct |
20 |
Correct |
65 ms |
8392 KB |
Output is correct |
21 |
Correct |
67 ms |
7884 KB |
Output is correct |
22 |
Correct |
66 ms |
9416 KB |
Output is correct |
23 |
Correct |
65 ms |
9412 KB |
Output is correct |
24 |
Correct |
67 ms |
9416 KB |
Output is correct |
25 |
Correct |
64 ms |
8136 KB |
Output is correct |
26 |
Correct |
63 ms |
8392 KB |
Output is correct |
27 |
Correct |
61 ms |
8392 KB |
Output is correct |
28 |
Correct |
64 ms |
9160 KB |
Output is correct |
29 |
Correct |
66 ms |
9428 KB |
Output is correct |
30 |
Correct |
62 ms |
8916 KB |
Output is correct |
31 |
Correct |
66 ms |
8988 KB |
Output is correct |
32 |
Correct |
69 ms |
8580 KB |
Output is correct |
33 |
Correct |
47 ms |
8916 KB |
Output is correct |
34 |
Correct |
68 ms |
8648 KB |
Output is correct |
35 |
Correct |
60 ms |
9416 KB |
Output is correct |
36 |
Correct |
60 ms |
9160 KB |
Output is correct |
37 |
Correct |
51 ms |
9672 KB |
Output is correct |
38 |
Correct |
56 ms |
9156 KB |
Output is correct |
39 |
Correct |
57 ms |
8388 KB |
Output is correct |
40 |
Correct |
55 ms |
8396 KB |
Output is correct |
41 |
Correct |
61 ms |
9416 KB |
Output is correct |
42 |
Correct |
60 ms |
9416 KB |
Output is correct |
43 |
Correct |
55 ms |
9288 KB |
Output is correct |
44 |
Correct |
68 ms |
8140 KB |
Output is correct |
45 |
Correct |
56 ms |
9468 KB |
Output is correct |
46 |
Correct |
55 ms |
8092 KB |
Output is correct |
47 |
Correct |
57 ms |
7632 KB |
Output is correct |
48 |
Correct |
61 ms |
9092 KB |
Output is correct |
49 |
Correct |
65 ms |
8392 KB |
Output is correct |
50 |
Correct |
65 ms |
9160 KB |
Output is correct |
51 |
Correct |
52 ms |
9156 KB |
Output is correct |
52 |
Correct |
43 ms |
7888 KB |
Output is correct |
53 |
Correct |
1 ms |
2392 KB |
Output is correct |
54 |
Correct |
69 ms |
7880 KB |
Output is correct |
55 |
Correct |
70 ms |
11720 KB |
Output is correct |
56 |
Correct |
83 ms |
17080 KB |
Output is correct |
57 |
Correct |
119 ms |
17348 KB |
Output is correct |
58 |
Correct |
119 ms |
18884 KB |
Output is correct |
59 |
Correct |
123 ms |
18560 KB |
Output is correct |
60 |
Correct |
91 ms |
18108 KB |
Output is correct |
61 |
Correct |
127 ms |
18620 KB |
Output is correct |
62 |
Correct |
118 ms |
18376 KB |
Output is correct |
63 |
Correct |
71 ms |
13256 KB |
Output is correct |
64 |
Correct |
91 ms |
17848 KB |
Output is correct |
65 |
Correct |
124 ms |
17600 KB |
Output is correct |
66 |
Correct |
118 ms |
17084 KB |
Output is correct |
67 |
Correct |
129 ms |
19100 KB |
Output is correct |
68 |
Correct |
50 ms |
12488 KB |
Output is correct |
69 |
Correct |
91 ms |
17212 KB |
Output is correct |
70 |
Correct |
73 ms |
13796 KB |
Output is correct |
71 |
Correct |
55 ms |
12744 KB |
Output is correct |
72 |
Correct |
54 ms |
13096 KB |
Output is correct |
73 |
Correct |
58 ms |
11192 KB |
Output is correct |
74 |
Correct |
57 ms |
12780 KB |
Output is correct |
75 |
Correct |
58 ms |
11100 KB |
Output is correct |
76 |
Correct |
67 ms |
11976 KB |
Output is correct |
77 |
Correct |
62 ms |
10712 KB |
Output is correct |
78 |
Correct |
58 ms |
12232 KB |
Output is correct |
79 |
Correct |
121 ms |
18368 KB |
Output is correct |
80 |
Correct |
68 ms |
12740 KB |
Output is correct |
81 |
Correct |
88 ms |
17344 KB |
Output is correct |
82 |
Correct |
106 ms |
18220 KB |
Output is correct |
83 |
Correct |
106 ms |
18376 KB |
Output is correct |
84 |
Correct |
124 ms |
17604 KB |
Output is correct |
85 |
Correct |
66 ms |
11976 KB |
Output is correct |
86 |
Correct |
55 ms |
11976 KB |
Output is correct |
87 |
Correct |
46 ms |
9928 KB |
Output is correct |
88 |
Correct |
130 ms |
17456 KB |
Output is correct |
89 |
Correct |
0 ms |
2392 KB |
Output is correct |
90 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
91 |
Halted |
0 ms |
0 KB |
- |