Submission #928514

#TimeUsernameProblemLanguageResultExecution timeMemory
92851412345678Sightseeing (NOI14_sightseeing)C++17
25 / 25
1769 ms201268 KiB
#include <bits/stdc++.h> using namespace std; const int nx=5e5+5; int n, m, q, u, v, w, dsu[nx], dp[nx]; vector<tuple<int, int, int>> ed; vector<pair<int, int>> d[nx]; void dfs(int u, int p) { for (auto [v, w]:d[u]) if (v!=p) dp[v]=min(dp[u], w), dfs(v, u); } int find(int x) { if (dsu[x]==x) return x; return dsu[x]=find(dsu[x]); } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>m>>q; for (int i=0; i<m; i++) cin>>u>>v>>w, ed.push_back({w, u, v}); sort(ed.begin(), ed.end()); reverse(ed.begin(), ed.end()); for (int i=1; i<=n; i++) dsu[i]=i; for (auto [w, u, v]:ed) if (find(u)!=find(v)) dsu[find(u)]=find(v), d[u].push_back({v, w}), d[v].push_back({u, w}); dp[1]=INT_MAX; dfs(1, 1); while (q--) cin>>u, cout<<dp[u]<<'\n'; } /* 4 4 2 1 2 10 1 3 30 2 4 20 3 4 5 3 4 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...