Submission #571420

#TimeUsernameProblemLanguageResultExecution timeMemory
571420duytuandao21Evacuation plan (IZhO18_plan)C++14
41 / 100
4072 ms71640 KiB
#include<bits/stdc++.h> #define fi first #define se second using namespace std; typedef pair<int,int> ii; const int N = 2e6+7; int n,m,k,q,NNP[N]; vector<ii> adj[N]; vector<int> dist(N,1e9+7); void DIJKSTRA() { priority_queue< ii, vector<ii>, greater<ii> > dt; for(int i=1;i<=n;i++) { if(NNP[i] == 1) { dist[i] = 0; dt.push({0,i}); } } while(!dt.empty()) { int u = dt.top().se; int val = dt.top().fi; dt.pop(); if(dist[u] != val) continue; for(ii w : adj[u]) { int v = w.se; int he = w.fi; if(dist[v] > he + val) { dist[v] = he + val; dt.push({dist[v], v}); } } } } bool check(int val,int x,int y) { queue<int> s; vector<int> ok(n+1,0); ok[x] = 1; if(dist[x] >= val) s.push(x); while(!s.empty()) { int u = s.front(); s.pop(); for(ii w : adj[u]) { int v = w.se; if(ok[v] == 0 && dist[v] >= val) { ok[v] = 1; s.push(v); } } } if(ok[y] == 1) return true; return false; } void solve(int u,int v) { int l = 0; int r = 1e8; int ans; while(l <= r) { int mid = (l + r) / 2; if(check(mid,u,v) == true) { ans = mid; l = mid + 1; } else r = mid - 1; } cout<<ans<<'\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=1;i<=m;i++) { int u,v,w; cin>>u>>v>>w; adj[u].push_back({w,v}); adj[v].push_back({w,u}); } cin>>k; while(k--) { int x; cin>>x; NNP[x] = 1; } DIJKSTRA(); cin>>q; while(q--) { int u,v; cin>>u>>v; solve(u,v); } //for(int i=1;i<=n;i++) cout<<dist[i]<<" "; return 0; }

Compilation message (stderr)

plan.cpp: In function 'void solve(int, int)':
plan.cpp:63:13: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |  cout<<ans<<'\n';
      |             ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...