結果
| 問題 |
No.748 yuki国のお財布事情
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-15 10:31:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 140 ms / 2,000 ms |
| コード長 | 1,362 bytes |
| コンパイル時間 | 1,278 ms |
| コンパイル使用メモリ | 103,452 KB |
| 実行使用メモリ | 5,580 KB |
| 最終ジャッジ日時 | 2024-06-15 10:31:28 |
| 合計ジャッジ時間 | 4,407 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std ;
int par[100002];
void init(int n){
for(int i = 0; i < n; i++){
par[i] = i;
}
}
int root(int x){
if(par[x] == x){
return x;
}else{
return par[x] = root(par[x]);
}
}
bool same(int x, int y){
return root(x) == root(y);
}
void unite(int x, int y){
int rx = root(x);
int ry = root(y);
if(rx == ry) return;
par[rx] = ry;
}
int main(){
int N,M,K;
cin >> N >> M >> K;
vector <pair<long long int,pair<int,int>>> r;
long long int maxcost = 0;
for(int i = 0; i < M; i++){
int a,b,c;
cin >> a >> b >> c;
r.push_back(make_pair(c,make_pair(a,b)));
maxcost += c;
}
init(N);
long long int cost = 0;
for(int i = 0; i < K; i++){
int e;
cin >> e;
unite(r[e-1].second.first,r[e-1].second.second);
cost += r[e-1].first;
}
sort(r.begin(), r.end());
for(int i = 0; i < M; i++){
if(!same(r[i].second.first,r[i].second.second)){
unite(r[i].second.first,r[i].second.second);
cost += r[i].first;
}
}
cout << maxcost - cost << endl;
return 0;
}