제출 #571408

#제출 시각아이디문제언어결과실행 시간메모리
571408duytuandao21Evacuation plan (IZhO18_plan)C++14
22 / 100
4035 ms65880 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,dist[N]; vector<ii> adj[N]; void DIJKSTRA(int x) { vector<int> d(n+1,1e9+7); d[x] = 0; priority_queue< ii, vector<ii>, greater<ii> > dt; dt.push({0,x}); while(!dt.empty()) { int u = dt.top().se; int val = dt.top().fi; dt.pop(); if(d[u] != val) continue; for(ii w : adj[u]) { int v = w.se; int he = w.fi; if(d[v] > he + val) { d[v] = he + val; dt.push({d[v], v}); } } } for(int i=1;i<=n;i++) dist[i] = min(dist[i], d[i]); } bool check(int val,int x,int y) { queue<int> s; int ok[n+1]; for(int i=1;i<=n;i++) ok[i] = 0; ok[x] = 1; if(dist[x] >= val) s.push(x); while(!s.empty()) { int u = s.front(); s.pop(); //cout<<u<<" "; 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 = 1e9; 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<=n;i++) dist[i] = 1e9+7; 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; dist[x] = 0; DIJKSTRA(x); } cin>>q; while(q--) { int u,v; cin>>u>>v; solve(u,v); } //for(int i=1;i<=n;i++) cout<<dist[i]<<" "; cout<<'\n'; //if(check(6,1,6)==true) cout<<"hayquadit"; //solve(1,6); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

plan.cpp: In function 'void solve(int, int)':
plan.cpp:62:13: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |  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...