Submission #104874

#TimeUsernameProblemLanguageResultExecution timeMemory
104874popovicirobertCrocodile's Underground City (IOI11_crocodile)C++14
0 / 100
2 ms384 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]}); } vector <bool> ext(N); for(int i = 0; i < K; i++) { ext[P[i]] = 1; } priority_queue <Comp> pq; vector <ll> dst(N); vector <bool> vis(N); for(int i = 0; i < N; i++) { dst[i] = INF; if(ext[i]) { continue; } vector <int> arr; for(auto it : g[i]) { if(ext[it.first]) { arr.push_back(it.second); } } sort(arr.begin(), arr.end()); if(arr.size() > 1) { pq.push({i, arr[1]}); dst[i] = arr[1]; } } while(pq.size()) { auto cur = pq.top(); pq.pop(); if(vis[cur.nod]) { continue; } vis[cur.nod] = 1; for(auto it : g[cur.nod]) { if(dst[it.first] > cur.val + it.second) { dst[it.first] = cur.val + it.second; pq.push({it.first, dst[it.first]}); } } } return dst[0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...