Submission #565813

#TimeUsernameProblemLanguageResultExecution timeMemory
565813RifalEvacuation plan (IZhO18_plan)C++14
10 / 100
76 ms468 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]; long long dist[M]; vector<pair<int,long long>> v[M]; void d(int s) { for(int i = 0; i < M; i++) { arr[i] = INF; } arr[s] = 0; priority_queue<pair<long long,int>, vector<pair<long long, int>>, greater<pair<long long,int>>> pq; pq.push({arr[s],s}); while(!pq.empty()) { pair<long long,int> tp = pq.top(); pq.pop(); if(arr[tp.second] < tp.first) continue; for(auto i : v[tp.second]) { if(arr[tp.second]+i.second < arr[i.first]) { arr[i.first] = arr[tp.second]+i.second; dist[i.first] = min(dist[i.first],arr[i.first]); pq.push({arr[i.first],i.first}); } } } } int main() { int n, m, k, q; cin >> n >> m; for(int i = 0; i <= n; i++){ dist[i] = INF; } 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]); dist[a[i]] = 0; } cin >> q; while(q--) { int s, t; cin >> s >> t; cout << min(dist[s],dist[t]) << 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...