# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
78667 | 2018-10-07T01:26:50 Z | thebes | Sightseeing (NOI14_sightseeing) | C++14 | 3084 ms | 257620 KB |
#include <bits/stdc++.h> using namespace std; const int MN = 5e5+5; int N, M, Q, i, x, y, ds[MN], ans[MN]; struct ed{int x, y, w;}e[10*MN]; int fnd(int x){return ds[x]=ds[x]==x?x:fnd(ds[x]);} vector<pair<int,int>> adj[MN]; void dfs(int n,int p,int w){ ans[n] = w; for(auto v : adj[n]) if(v.first!=p) dfs(v.first,n,min(w,v.second)); } int main(){ for(scanf("%d%d%d",&N,&M,&Q),i=1;i<=M;i++) scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].w); sort(e+1,e+M+1,[](ed i,ed j){return i.w>j.w;}); for(i=1;i<=N;i++) ds[i]=i; for(i=1;i<=M;i++){ x=e[i].x, y=e[i].y; if(fnd(x)!=fnd(y)){ ds[fnd(x)]=fnd(y); adj[x].push_back({y,e[i].w}); adj[y].push_back({x,e[i].w}); } } dfs(1, 0, 1<<30); for(;Q;Q--){ scanf("%d",&x); printf("%d\n",ans[x]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12152 KB | Output is correct |
2 | Correct | 11 ms | 12288 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 12396 KB | Output is correct |
2 | Correct | 13 ms | 12396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 15464 KB | Output is correct |
2 | Correct | 43 ms | 16156 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2036 ms | 125620 KB | Output is correct |
2 | Correct | 3084 ms | 257620 KB | Output is correct |