#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,0);
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 |
40 ms |
8916 KB |
Output is correct |
3 |
Correct |
39 ms |
8608 KB |
Output is correct |
4 |
Correct |
40 ms |
9672 KB |
Output is correct |
5 |
Correct |
39 ms |
8200 KB |
Output is correct |
6 |
Correct |
40 ms |
9684 KB |
Output is correct |
7 |
Correct |
40 ms |
9168 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 |
40 ms |
8916 KB |
Output is correct |
3 |
Correct |
39 ms |
8608 KB |
Output is correct |
4 |
Correct |
40 ms |
9672 KB |
Output is correct |
5 |
Correct |
39 ms |
8200 KB |
Output is correct |
6 |
Correct |
40 ms |
9684 KB |
Output is correct |
7 |
Correct |
40 ms |
9168 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Incorrect |
61 ms |
8136 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
40 ms |
8916 KB |
Output is correct |
3 |
Correct |
39 ms |
8608 KB |
Output is correct |
4 |
Correct |
40 ms |
9672 KB |
Output is correct |
5 |
Correct |
39 ms |
8200 KB |
Output is correct |
6 |
Correct |
40 ms |
9684 KB |
Output is correct |
7 |
Correct |
40 ms |
9168 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Incorrect |
61 ms |
8136 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
40 ms |
8916 KB |
Output is correct |
3 |
Correct |
39 ms |
8608 KB |
Output is correct |
4 |
Correct |
40 ms |
9672 KB |
Output is correct |
5 |
Correct |
39 ms |
8200 KB |
Output is correct |
6 |
Correct |
40 ms |
9684 KB |
Output is correct |
7 |
Correct |
40 ms |
9168 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Incorrect |
61 ms |
8136 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
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 |
40 ms |
8916 KB |
Output is correct |
3 |
Correct |
39 ms |
8608 KB |
Output is correct |
4 |
Correct |
40 ms |
9672 KB |
Output is correct |
5 |
Correct |
39 ms |
8200 KB |
Output is correct |
6 |
Correct |
40 ms |
9684 KB |
Output is correct |
7 |
Correct |
40 ms |
9168 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Incorrect |
61 ms |
8136 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |