Submission #78667

#TimeUsernameProblemLanguageResultExecution timeMemory
78667thebesSightseeing (NOI14_sightseeing)C++14
25 / 25
3084 ms257620 KiB
#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 (stderr)

sightseeing.cpp: In function 'int main()':
sightseeing.cpp:15:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(scanf("%d%d%d",&N,&M,&Q),i=1;i<=M;i++)
         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
sightseeing.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].w);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x);
         ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...