제출 #977301

#제출 시각아이디문제언어결과실행 시간메모리
977301steveonalex통행료 (APIO13_toll)C++17
16 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define ALL(v) (v).begin(), (v).end() #define MASK(i) (1LL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) // mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng(1); ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;} ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll LASTBIT(ll mask){return mask & (-mask);} ll pop_cnt(ll mask){return __builtin_popcountll(mask);} ll ctz(ll mask){return __builtin_ctzll(mask);} ll clz(ll mask){return __builtin_clzll(mask);} ll logOf(ll mask){return 63 - clz(mask);} template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b){a = b; return true;} return false; } template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b){a = b; return true;} return false; } template <class T> void printArr(T a, string separator = " ", string finish = "\n", ostream& out = cout){ for(auto i: a) out << i << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } const int N = 1e5 + 69; int n, m, k; int p[N]; struct DSU{ int n; vector<int> parent; vector<ll> sz; DSU(int _n){ n = _n; parent.resize(n+1); sz.resize(n+1, 1); for(int i = 0; i<=n; ++i) parent[i] = i; } int find_set(int u){return (u == parent[u]) ? u : (parent[u] = find_set(parent[u]));} bool same_set(int u, int v){return find_set(u) == find_set(v);} bool join_set(int u, int v){ u = find_set(u), v = find_set(v); if (u != v){ if (sz[u] < sz[v]) swap(u, v); parent[v] = u; sz[u] += sz[v]; return true; } return false; } ll get_sz(int u){return sz[find_set(u)];} }; int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; vector<array<int, 3>> path(m); for(int i= 0; i<m; ++i) for(int j = 0; j<3; ++j) cin >> path[i][j]; int u, v; cin >> u >> v; sort(ALL(path), [](array<int, 3> a, array<int, 3> b){ return a[2] < b[2]; }); DSU mst(n); for(int i = 1; i<=n; ++i) cin >> mst.sz[i]; int peak_w = 1e9 + 69; for(array<int, 3> i: path) { u = mst.find_set(u), v = mst.find_set(v); int _u = mst.find_set(i[0]), _v= mst.find_set(i[1]); if (u > v) swap(u, v); if (_u > _v) swap(_u, _v); if (u == _u && v == _v) { minimize(peak_w, i[2]); } else mst.join_set(i[0], i[1]); } ll ans; if (mst.same_set(u, 1)) { ans = 1LL * peak_w * mst.get_sz(v); } else { ans = 1LL * peak_w * mst.get_sz(u); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...