Submission #960289

#TimeUsernameProblemLanguageResultExecution timeMemory
960289thinknoexitSecurity Guard (JOI23_guard)C++17
0 / 100
9 ms7228 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 100100; int a[N]; vector<int> adj[N]; struct A { int u, v; bool operator < (const A& o) const { return min(a[u], a[v]) < min(a[o.u], a[o.v]); } }; ll ans = 0; vector<A> e; int p[N]; int fr(int i) { return p[i] == i ? i : p[i] = fr(p[i]); } void dfs(int v, int p = -1) { for (auto& x : adj[v]) { if (x == p) continue; ans += a[v]; dfs(x, v); } } int main() { cin.tie(nullptr)->sync_with_stdio(false); int n, m, q; cin >> n >> m >> q; if (m != n - 1) return 0; for (int i = 1;i <= n;i++) { cin >> a[i]; p[i] = i; } while (m--) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } int idx = max_element(a + 1, a + 1 + n) - a; dfs(idx); cout << ans; 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...