Submission #51232

#TimeUsernameProblemLanguageResultExecution timeMemory
51232robertSightseeing (NOI14_sightseeing)C++14
15 / 25
3549 ms111024 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; typedef pair<int, int> ii; vector<vector<ii > > g; ii UFDS[500100]; int d[500100]; void dfs(int n, int p, int minv){ d[n] = minv; for(int x=0; x<g[n].size(); x++){ if(g[n][x].first!=p){ dfs(g[n][x].first, n, min(minv, g[n][x].second)); } } } int p(int n){ if(n==UFDS[n].first) return n; return UFDS[n].first = p(UFDS[n].first); } int merge(int a, int b){ a = p(a); b = p(b); if(UFDS[a].second<UFDS[b].second){ UFDS[a].first = b; } else if(UFDS[a].second>UFDS[b].second){ UFDS[b].first = a; } else { UFDS[a].first = b; UFDS[b].second++; } } int main(){ int N, M, Q; scanf("%d %d %d", &N, &M, &Q); g.assign(N+1, vector<ii >()); int a, b, c; priority_queue<pair<int, ii> > q; for(int m=0; m<M; m++){ scanf("%d %d %d", &a, &b, &c); q.push({c, {a, b}}); } for(int n=0; n<=N; n++) UFDS[n] = {n, 1}; while(!q.empty()){ pair<int, ii> t = q.top(); q.pop(); if(p(t.second.first)!=p(t.second.second)){ merge(t.second.first, t.second.second); g[t.second.first].push_back({t.second.second, t.first}); g[t.second.second].push_back({t.second.first, t.first}); } } dfs(1, -1, 1e9); for(int q=0; q<Q; q++){ int a; scanf("%d", &a); printf("%d\n", d[a]); } return 0; }

Compilation message (stderr)

sightseeing.cpp: In function 'void dfs(int, int, int)':
sightseeing.cpp:14:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int x=0; x<g[n].size(); x++){
               ~^~~~~~~~~~~~
sightseeing.cpp: In function 'int merge(int, int)':
sightseeing.cpp:38:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
sightseeing.cpp: In function 'int main()':
sightseeing.cpp:41:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N, M, Q; scanf("%d %d %d", &N, &M, &Q);
               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a);
   ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...