제출 #51742

#제출 시각아이디문제언어결과실행 시간메모리
51742hugo_pmEvacuation plan (IZhO18_plan)C++14
23 / 100
1213 ms27260 KiB
#include <bits/stdc++.h> #pragma GCC diagnostic ignored "-Wunused-result" using namespace std; typedef pair<int, int> pii; typedef priority_queue<pii, vector<pii>, greater<pii>> MaxHeap; const int INF = (INT_MAX - 3) / 2; const int borneMax = (int)(1e5) + 5; int nbNod, nbArc, nbCen, nbReq; vector<pii> adj[borneMax]; vector<int> cen; vector<int> minDist(borneMax, INF); void lireEntree() { scanf("%d%d", &nbNod, &nbArc); for (int ind = 0; ind < nbArc; ++ind) { int nod1, nod2, poids; scanf("%d%d%d", &nod1, &nod2, &poids); adj[nod1].push_back({nod2, poids}); adj[nod2].push_back({nod1, poids}); } scanf("%d", &nbCen); cen.resize(nbCen); for (int ind = 0; ind < nbCen; ++ind) { scanf("%d", &cen[ind]); } } void preparer() { MaxHeap dij; for (int nod : cen) { dij.push({nod, 0}); minDist[nod] = 0; } while (! dij.empty()) { auto e = dij.top(); int nod = e.first, dis = e.second; dij.pop(); if (dis > minDist[nod]) continue; for (pii obj : adj[nod]) { int voisin = obj.first, poids = obj.second; if (dis + poids < minDist[voisin]) { minDist[voisin] = dis + poids; dij.push({voisin, dis + poids}); } } } } int main() { lireEntree(); preparer(); scanf("%d", &nbReq); for (int ind = 0; ind < nbReq; ++ind) { int nod1, nod2; scanf("%d%d", &nod1, &nod2); printf("%d\n", min(minDist[nod1], minDist[nod2])); } }
#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...