Submission #814748

#TimeUsernameProblemLanguageResultExecution timeMemory
814748antonSightseeing (NOI14_sightseeing)C++17
15 / 25
922 ms262144 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> struct Edge{ int a, b; int c; Edge(){}; bool operator<(const Edge& b)const{ return c<b.c; } Edge(int _a, int _b, int _c){ a = _a; b= _b; c= _c; } }; const int MAX_V = 5*1e5; const int MAX_E = 5*1e6; int v, e, q; vector<pii> adj[MAX_V]; Edge edges[MAX_E]; int dsu[MAX_V], sz[MAX_V]; int cost[MAX_V]; int get_C(int id){ if(dsu[id]==-1){ return id; } else{ int anc= get_C(dsu[id]); dsu[id] = anc; return anc; } } void merge(int a, int b){ a = get_C(a); b = get_C(b); if(sz[a]<sz[b]){ swap(a, b); } dsu[b] = a; sz[a] += sz[b]; } void dfs(int u, int c, int anc){ cost[u] = c; for(auto v: adj[u]){ if(v.first!=anc){ dfs(v.first, min(c, v.second), u); } } } signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin>>v>>e>>q; for(int i = 0; i<e; i++){ int a, b; int c; cin>>a>>b; a--;b--; cin>>c; edges[i] = Edge(a, b, c); } sort(edges, edges+e); fill(dsu, dsu+e, -1); fill(sz, sz+e, 1); for(int i = e-1; i>=0; i--){ int a= edges[i].a; int b= edges[i].b; if(get_C(a)!=get_C(b)){ adj[a].push_back(pii(b, edges[i].c)); adj[b].push_back(pii(a, edges[i].c)); merge(a, b); } } dfs(0, 1e18, -1); for(int i = 0; i<q; i++){ int u; cin>>u; cout<<cost[u-1]<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...