이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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<int> al[200005];
int p[200005];
int par(int i){
if (p[i]==i) return p[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];
rep(x,0,m){
int a,b; cin>>a>>b;
if (ii(arr[a],a)<ii(arr[b],b)) swap(a,b);
al[a].pub(b);
}
vector<int> idx;
rep(x,1,n+1) idx.pub(x);
sort(all(idx),[](int i,int j){
return ii(arr[i],i)<ii(arr[j],j);
});
rep(x,1,n+1) sort(all(al[x]),[](int i,int j){ return arr[i]<arr[j]; });
rep(x,1,n+1) p[x]=x;
int ans=0;
for (auto u:idx){
for (auto v:al[u]) if (par(v)!=u){
ans+=arr[u]-arr[par(v)]+arr[v];
p[par(v)]=u;
}
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |