Submission #104877

#TimeUsernameProblemLanguageResultExecution timeMemory
104877popovicirobertCrocodile's Underground City (IOI11_crocodile)C++14
100 / 100
1478 ms92424 KiB
#include "crocodile.h" #include <bits/stdc++.h> #define ll long long using namespace std; const ll INF = 1e18; struct Comp { int nod; ll val; bool operator <(const Comp &other) const { return val > other.val; } }; int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { vector < vector < pair <int, int> > > g(N); for(int i = 0; i < M; i++) { g[R[i][0]].push_back({R[i][1], L[i]}); g[R[i][1]].push_back({R[i][0], L[i]}); } priority_queue <Comp> pq; vector <ll> dst(N, INF); vector <int> cnt(N); for(int i = 0; i < K; i++) { dst[P[i]] = 0; pq.push({P[i], 0}); cnt[P[i]] = 1; } while(pq.size()) { auto cur = pq.top(); pq.pop(); if(cnt[cur.nod] == 2) { continue; } cnt[cur.nod]++; dst[cur.nod] = cur.val; if(cnt[cur.nod] == 2) { for(auto it : g[cur.nod]) { pq.push({it.first, cur.val + it.second}); } } } return (int) dst[0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...