Submission #29469

#TimeUsernameProblemLanguageResultExecution timeMemory
29469samir_droubiSightseeing (NOI14_sightseeing)C++14
15 / 25
3500 ms93576 KiB
#include <bits/stdc++.h> using namespace std; int n,m,q; const int mxn=(5e5)+5; vector<pair<int,int> >gr[mxn]; int ans[mxn]; set<pair<int,int> >s; int main() { scanf("%d%d%d",&n,&m,&q); for(int i=0;i<m;++i) { int x,y,w; scanf("%d%d%d",&x,&y,&w); gr[x].push_back({y,w}); gr[y].push_back({x,w}); } memset(ans,-1,sizeof ans); ans[1]=(1e9); s.insert({ans[1],1}); while(!s.empty()) { set< pair<int,int> >::iterator it=s.end(); --it; int vl=it->first; int v=it->second; s.erase(it); if(vl<ans[v])continue; ans[v]=vl; for(int i=0;i<gr[v].size();++i) { int u=gr[v][i].first; int w=gr[v][i].second; if(min(vl,w)>ans[u]) s.insert({min(vl,w),u}); } } while(q--) { int x; scanf("%d",&x); printf("%d\n",ans[x]); } return 0; }

Compilation message (stderr)

sightseeing.cpp: In function 'int main()':
sightseeing.cpp:30:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<gr[v].size();++i)
                      ^
sightseeing.cpp:10:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&m,&q);
                             ^
sightseeing.cpp:14:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&x,&y,&w);
                                 ^
sightseeing.cpp:41:23: 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...