# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
140375 | 2019-08-02T16:41:27 Z | muradeyn | Crocodile's Underground City (IOI11_crocodile) | C++14 | 0 ms | 0 KB |
#include "crocodile.h" #include <bits/stdc++.h> #define F first #define S second using namespace std; const int maxx = 100000; int x , y; int ext[maxx]; long long min1[maxx] , min2[maxx]; vector< pair<long long,int> >v[maxx]; priority_queue< pair<long long,int> >pq; void dijkstra() { while (!pq.empty()) { int x = pq.top().S; long long y = pq.top().F; pq.pop(); y *= -1; if (!ext[x] && y > min2[x])continue; for (auto to : v[x]) { if (min1[to.F] == -1) { min1[to.F] = y + to.S; continue; } if (min2[to.F] == -1) { min2[to.F] = y + to.S; if (min2[to.F] < min1[to.F])swap(min2[to.F] , min1[to.F]); pq.push({-min2[to.F] , to.F}); continue; } if (y + to.S < min1[to.F]) { min2[to.F] = min1[to.F]; min1[to.F] = y + to.S; pq.push({-min2[to.F] , to.F}); continue; } if (y + to.S < min2[to.F]) { min2[to.F] = y + to.S; pq.push({-min2[to.F] , to.F}); continue; } } } } long long travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) { for (int i = 0;i<n;i++) min1[i] = min2[i] = -1; for (int i = 0;i<k;i++)ext[p[i]] = 1 , pq.push({0 , p[i]}); for (int i = 0;i<m;i++) { x = r[i][0]; y = r[i][1]; if (!ext[x])v[y].push_back({x , l[i]}); if (!ext[y])v[x].push_back({y , l[i]}); } dijkstra(); return min2[0]; }