Submission #960522

#TimeUsernameProblemLanguageResultExecution timeMemory
960522thinknoexitSecurity Guard (JOI23_guard)C++17
37 / 100
135 ms21564 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 200200; int a[N]; struct A { int v; ll w; bool operator < (const A& o) const { return w > o.w; } }; priority_queue<A> pq; int p[N]; ll dis[N]; bool vis[N]; vector<int> adj[N]; ll ans = 0; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n, m, q; cin >> n >> m >> q; for (int i = 1;i <= n;i++) { cin >> a[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; memset(dis, 0x3f, sizeof dis); dis[idx] = 0; pq.push({ idx, 0 }); while (!pq.empty()) { auto x = pq.top(); pq.pop(); int v = x.v; if (dis[v] < x.w) continue; for (auto& x : adj[v]) { if (dis[x] > dis[v] + a[v]) { p[x] = v; dis[x] = dis[v] + a[v]; pq.push({ x, dis[x] }); } } } for (int i = 1;i <= n;i++) { ans += a[p[i]]; } 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...