제출 #565799

#제출 시각아이디문제언어결과실행 시간메모리
565799RifalEvacuation plan (IZhO18_plan)C++14
10 / 100
224 ms27236 KiB
#include <bits/stdc++.h> #include <fstream> #define endl '\n' #define mod 32768 #define INF 100000000000000 //#define ll long long //#define cin fin //#define cout fout using namespace std; //ofstream fout("convention.out"); //ifstream fin("convention.in"); const int M = 1e3 + 5; long long arr[M][M]; vector<pair<int,long long>> v[M]; void d(int s) { for(int i = 0; i < M; i++) { arr[s][i] = INF; } arr[s][s] = 0; priority_queue<pair<long long,int>, vector<pair<long long, int>>, greater<pair<long long,int>>> pq; pq.push({arr[s][s],s}); while(!pq.empty()) { pair<long long,int> tp = pq.top(); pq.pop(); if(arr[s][tp.second] < tp.first) continue; for(auto i : v[tp.second]) { if(arr[s][tp.second]+i.second < arr[s][i.first]) { arr[s][i.first] = arr[s][tp.second]+i.second; pq.push({arr[s][i.first],i.first}); } } } } int main() { int n, m, k, q; cin >> n >> m; for(int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; v[a].push_back({b,c}); v[b].push_back({a,c}); } cin >> k; int a[k]; for(int i = 0; i < k; i++) { cin >> a[i]; d(a[i]); } cin >> q; while(q--) { int s, t; cin >> s >> t; long long ans = INF; for(int i = 0; i < k; i++) { ans = min(ans,arr[a[i]][s]); ans = min(ans,arr[a[i]][t]); } cout << ans << endl; } return 0; }
#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...