이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+5;
int n, m, q;
typedef long long ll;
typedef array<int, 2> ar2;
int uf[MAXN];
int val[MAXN];
ar2 edges[2*MAXN];
int find(int i) {
	return uf[i] == i ? i : uf[i] = find(uf[i]);
}
int wt(ar2 i) {
	return val[i[0]] + val[i[1]];
}
struct cmp {
	bool operator()(ar2 i, ar2 j) {
		return ar2({wt(i), i[0]}) < ar2({wt(j), j[0]});
	}
} cmp;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m >> q;
	assert(q == 0);
	iota(uf, uf+n, 0);
	ll s = 0;
	int mx = 0;
	for (int i = 0; i < n; i++) {
		cin >> val[i];
		s -= val[i];
		mx = max(val[i], mx);
	}
	s += mx;
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		edges[i] = {a-1, b-1};
	}
	sort(edges, edges+m, cmp);
	for (int i = 0; i < m; i++) {
		int a = find(edges[i][0]);
		int b = find(edges[i][1]);
		int v = wt(edges[i]);
		if (a != b) {
			uf[a] = b;
			s += v;
		}
	}
	cout << s << '\n';
}
| # | 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... |