Submission #652821

#TimeUsernameProblemLanguageResultExecution timeMemory
652821raysh07Sightseeing (NOI14_sightseeing)C++14
15 / 25
1575 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define int long long mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 5e6 + 69; int d[maxn]; int sz[maxn]; int root[maxn]; vector <int> st[maxn]; int ans[maxn]; int findroot(int x) { while (x!=root[x]) x = root[x]; return x; } void unite(int x, int y) { if (x==y) return; if (sz[x]<sz[y]) swap(x, y); sz[x] += sz[y]; root[y] = x; for (int i=0; i<(int)(st[y].size()); i++) st[x].push_back(st[y][i]); st[y].clear(); } void Solve() { int v, e, q; cin>>v>>e>>q; vector <pair<int, pair<int, int>>> edg; for (int i=0; i<e; i++) { int a, b, c; cin>>a>>b>>c; a--; b--; edg.push_back(make_pair(c, make_pair(a, b))); } sort(edg.begin(), edg.end(), greater<pair<int, pair<int, int>>>()); for (int i=0; i<v; i++) { sz[i] = 1; root[i] = i; st[i].push_back(i); } for (int i=0; i<e; i++) { int u = edg[i].second.first; int v = edg[i].second.second; u = findroot(u); v = findroot(v); int w = findroot(0); if (v==w) { swap(u, v); } if (u==w && v!=w) { //cout<<"YES "<<i+1<<" "<<v+1<<"\n"; for (int j=0; j<(int)(st[v].size()); j++) { //cout<<"UPDATED "<<st[v][j] + 1<<" "<<edg[i].first<<"\n"; ans[st[v][j]] = edg[i].first; } } unite(u, v); } for (int i=0; i<q; i++) { int x; cin>>x; x--; cout<<ans[x]<<"\n"; } } int32_t main() { //freopen(".in", "r", stdin); //freopen(".out", "w", stdout); auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; for(int i = 1; i <= t; i++) { //cout << "Case #" << i << ": "; Solve(); } auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 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...