# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1072253 | 2024-08-23T16:03:20 Z | dwuy | Crocodile's Underground City (IOI11_crocodile) | C++14 | 0 ms | 0 KB |
/** - dwuy - /> フ | _ _| /`ミ _x ノ / | / ヽ ? / ̄| | | | | ( ̄ヽ__ヽ_)_) \二つ **/ #include <bits/stdc++.h> #include "crocodile.h" #define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL) #define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout) #define fi first #define se second #define endl "\n" #define len(s) (int)((s).size()) #define MASK(k)(1LL<<(k)) #define TASK "test" using namespace std; typedef tuple<int, int, int> tpiii; typedef pair<double, double> pdd; typedef pair<int, int> pii; typedef long long ll; const long long OO = 1e18; const int MOD = 1e9 + 7; const int INF = 1e9; const int MX = 100005; ll n, m; ll d[MX]; ll cnt[MX]; vector<pii> G[MX]; ll travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){ n = N; m = M; for(int i=0; i<m; i++){ int u = R[i][0] + 1; int v = R[i][1] + 1; int c = L[i]; G[u].push_back({v, c}); G[v].push_back({u, c}); } priority_queue<pii, vector<pii>, greater<pii>> Q; memset(d, 0x3f, sizeof d); memset(cnt, 0, sizeof cnt); for(int i=0; i<K; i++){ int u = P[i] + 1; Q.push({0, u}); d[u] = 0; cnt[u] = 1; } while(Q.size()){ ll du, u; tie(du, u) = Q.top(); Q.pop(); cnt[u]++; if(cnt[u] != 2) continue; d[u] = du; for(pii edge: G[u]){ ll v, c; tie(v, c) = edge; Q.push({du + c, v}); } } return (d[1] == d[0]? -1 : d[1]); }