Submission #675477

#TimeUsernameProblemLanguageResultExecution timeMemory
675477QwertyPiSightseeing (NOI14_sightseeing)C++14
15 / 25
3551 ms127228 KiB
#include <bits/stdc++.h> using namespace std; struct edge{ int u, v, w; bool operator< (const edge& o) { return w < o.w; } }; struct qry{ int x, i; bool operator< (const qry& o) { return x < o.x; } }; const int MAXN = 5e5 + 11; int ans[MAXN]; int dsu[MAXN]; vector<int> sons[MAXN]; void init(int n){ for(int i = 1; i <= n; i++) dsu[i] = i, sons[i].push_back(i); } int f(int x){ return x == dsu[x] ? x : dsu[x] = f(dsu[x]); } void g(int x, int y, int w){ x = f(x), y = f(y); if(x == y) return; if(f(1) == f(y)) swap(x, y); if(f(1) == f(x)){ for(auto i : sons[y]){ ans[i] = w; } }else{ if(sons[x].size() < sons[y].size()) swap(x, y); for(auto i : sons[y]){ sons[x].push_back(i); } } sons[y].clear(); dsu[y] = x; } vector<edge> E[MAXN]; int main(){ int n, m, q; cin >> n >> m >> q; for(int i = 0; i < m; i++){ int u, v, w; cin >> u >> v >> w; E[w].push_back({u, v, w}); } init(n); for(int j = MAXN - 1; j >= 0; j--){ for(auto e : E[j]){ g(e.u, e.v, e.w); } } for(int i = 0; i < q; i++){ int x; cin >> x; cout << ans[x] << 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...