Submission #29475

#TimeUsernameProblemLanguageResultExecution timeMemory
29475samir_droubiSightseeing (NOI14_sightseeing)C++14
15 / 25
3500 ms123900 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]; int mn=(1e9); vector<int>e[mxn]; void dfs(int v) { ans[v]=mn; for(int i=0;i<gr[v].size();++i) { int u=gr[v][i].first; int w=gr[v][i].second; if(ans[u]!=-1)continue; if(w>=mn)dfs(u); else e[w].push_back(u); } } 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); dfs(1); for(int i=(1e5);i>=0;--i) { mn=i; for(int j=0;j<e[i].size();++j) { int v=e[i][j]; if(ans[v]!=-1)continue; dfs(v); } } while(q--) { int x; scanf("%d",&x); printf("%d\n",ans[x]); } return 0; }

Compilation message (stderr)

sightseeing.cpp: In function 'void dfs(int)':
sightseeing.cpp:12:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<gr[v].size();++i)
                  ^
sightseeing.cpp: In function 'int main()':
sightseeing.cpp:37:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<e[i].size();++j)
                      ^
sightseeing.cpp:23: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:27: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:47: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...