# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1087958 | 2024-09-13T15:36:35 Z | T0p_ | Crocodile's Underground City (IOI11_crocodile) | C++14 | 0 ms | 0 KB |
#include "crocodile.h" #include <bits/stdc++.h> using namespace std; const int MAX_N = 100000 + 5; int degree[MAX_N]; long long mn_1[MAX_N], mn_2[MAX_N]; bool is_process[MAX_N]; vector<pair<int, long long>> g[MAX_N]; void update(int u, long long v) { if (v < mn_1[u]) { mn_2[u] = mn_1[u]; mn_1[u] = v; } else { mn_2[u] = min(mn_2[u], v); } } int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { for (int i=0 ; i<N ; i++) { mn_1[i] = mn_2[i] = 2e9; } 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] }); degree[R[i][0]]++; degree[R[i][1]]++; } queue<int> topo; for (int i=0 ; i<K ; i++) { is_process[P[i]] = true; topo.push(P[i]); mn_1[P[i]] = mn_2[P[i]] = 0; } while (!topo.empty()) { int u = topo.front(); topo.pop(); for (pair<int, long long> edge : g[u]) { degree[edge.first]--; update(edge.first, mn_2[u] + edge.second); if (i != 0 && !is_process[edge.first] && degree[edge.first] == 1) { is_process[edge.first] = true; topo.push(edge.first); } } } return mn_2[0]; }