結果
問題 | No.748 yuki国のお財布事情 |
ユーザー |
![]() |
提出日時 | 2018-12-06 22:55:39 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 1,271 bytes |
コンパイル時間 | 1,564 ms |
コンパイル使用メモリ | 169,420 KB |
実行使用メモリ | 7,788 KB |
最終ジャッジ日時 | 2024-09-14 02:36:04 |
合計ジャッジ時間 | 4,053 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define Would #define you #define please int P[100001]; int Find(int A) { if (P[A] == A) return A; P[A] = Find(P[A]); return P[A]; } void Union(int A, int B) { int C = Find(A); int D = Find(B); P[C] = D; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M, K; cin >> N >> M >> K; vector<pair<int, pair<int, int>>> V; rep(i, M) { int a, b, c; cin >> a >> b >> c; V.pb(mp(c, mp(a, b))); } int E[100001] = {}; rep(i, K) { int e; cin >> e; E[e - 1] = 1; } vector<pair<int, pair<int, int>>> V2, V3; rep(i, M) { if(E[i]) V2.pb(V[i]); else V3.pb(V[i]); } rep1(i, N) P[i] = i; for (auto i : V2) { Union(i.second.first, i.second.second); } sort(V3.begin(), V3.end()); ll kotae = 0; for (auto i : V3) { if (Find(i.second.first) != Find(i.second.second)) { Union(i.second.first, i.second.second); } else kotae += i.first; } co(kotae); Would you please return 0; }