Submission #943218

#TimeUsernameProblemLanguageResultExecution timeMemory
943218alextodoranSecurity Guard (JOI23_guard)C++17
50 / 100
164 ms13732 KiB
/** _ _ __ _ _ _ _ _ _ |a ||t ||o d | |o | | __ _| | _ | __| _ | | __ |/_ | __ /__\ / _\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N_MAX = 200000; const int M_MAX = 400000; const int Q_MAX = 200000; int N, M, Q; int S[N_MAX + 2]; int edge_u[M_MAX + 2], edge_v[M_MAX + 2]; int order[M_MAX + 2]; int root[N_MAX + 2]; int find_root (int u) { return (root[u] == 0 ? u : root[u] = find_root(root[u])); } bool join (int u, int v) { u = find_root(u); v = find_root(v); if (u != v) { root[u] = v; return true; } return false; } int main () { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N >> M >> Q; assert(Q == 0); for (int u = 1; u <= N; u++) { cin >> S[u]; } for (int i = 1; i <= M; i++) { cin >> edge_u[i] >> edge_v[i]; } iota(order + 1, order + M + 1, 1); sort(order + 1, order + M + 1, [&] (const int &i, const int &j) { return S[edge_u[i]] + S[edge_v[i]] < S[edge_u[j]] + S[edge_v[j]]; }); ll answer = 0; for (int _ = 1; _ <= M; _++) { int i = order[_]; if (join(edge_u[i], edge_v[i]) == true) { answer += S[edge_u[i]] + S[edge_v[i]]; } } int mx = 0; for (int u = 1; u <= N; u++) { answer -= S[u]; mx = max(mx, S[u]); } answer += mx; cout << answer << "\n"; return 0; }
#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...