# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
408839 | 2021-05-19T17:51:21 Z | SirCovidThe19th | Crocodile's Underground City (IOI11_crocodile) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; int travel_plan(int n, int m, int k, int r[][2], int l[], int p[]){ vector<vector<pair<int, int>>> adj(n); for (int i = 0; i < m; i++){ adj[r[i][0]].push_back({r[i][1], l[i]}); adj[r[i][1]].push_back({r[i][0], l[i]}); } priority_queue<pair<long long, int>> trav; vector<int> visited(n, 0); for (int i = 0; i < k; i++){ visited[p[i]] = 1; trav.push({0, p[i]}); } while (!trav.empty()){ pair<long long, int> curr = trav.top(); trav.pop(); visited[curr.second]++; if (visited[curr.second] == 2 and curr.second == 0) return -curr.first; if (visited[curr.second] == 2) for (pair<int, int> elem : adj[curr.second]) if (visited[elem.first] != 2) trav.push({curr.first-elem.second, elem.first}); } }