結果
| 問題 |
No.748 yuki国のお財布事情
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-12-03 20:26:18 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 52 ms / 2,000 ms |
| コード長 | 1,253 bytes |
| コンパイル時間 | 3,189 ms |
| コンパイル使用メモリ | 261,564 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-03 20:26:24 |
| 合計ジャッジ時間 | 5,291 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)
#define all(a) (a).begin(),(a).end()
#include <atcoder/dsu>
using namespace atcoder;
const ll INF = 1ll << 60;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int N, M, K;
cin >> N >> M >> K;
if (N == 1) {
cout << 0 << '\n';
return 0;
}
vector<pair<ll, pair<int, int>>> E(M);
ll ans = 0;
rep(i, 0, M) {
cin >> E[i].second.first >> E[i].second.second >> E[i].first;
E[i].second.first--;
E[i].second.second--;
ans += E[i].first;
}
dsu uf(N);
rep(i, 0, K) {
int e;
cin >> e;
e--;
uf.merge(E[e].second.first, E[e].second.second);
ans -= E[e].first;
E[e].first = INF;
}
sort(all(E));
while (true) {
if (E.back().first == INF) E.pop_back();
else break;
}
rep(i, 0, E.size()) {
if (!uf.same(E[i].second.first, E[i].second.second)) {
uf.merge(E[i].second.first, E[i].second.second);
ans -= E[i].first;
}
}
cout << ans << '\n';
}