Submission #1064805

#TimeUsernameProblemLanguageResultExecution timeMemory
1064805GusterGoose27Security Guard (JOI23_guard)C++17
50 / 100
120 ms12384 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...