# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
408831 | 2021-05-19T17:39:50 Z | SirCovidThe19th | 악어의 지하 도시 (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){ visited[curr.second]++; for (pair<int, int> elem : adj[curr.second]) if (visited[elem.second] != 2) trav.push({-(curr.first+elem.second), elem.first}); } } }