結果
| 問題 | No.748 yuki国のお財布事情 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-07 16:03:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 133 ms / 2,000 ms |
| コード長 | 2,200 bytes |
| コンパイル時間 | 1,959 ms |
| コンパイル使用メモリ | 180,284 KB |
| 実行使用メモリ | 7,140 KB |
| 最終ジャッジ日時 | 2024-07-03 09:26:36 |
| 合計ジャッジ時間 | 4,668 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
struct edge{
int from,to;
ll cost;
edge(int cost,int from,ll to):cost(cost),from(from),to(to){}
bool operator< (const edge &right){ return cost < right.cost;}
bool operator> (const edge &right){ return cost > right.cost;}
bool operator<= (const edge &right){ return cost <= right.cost;}
bool operator>= (const edge &right){ return cost >= right.cost;}
};
struct Unionfind{
vector<int> parents;
int m;
Unionfind(int n):parents(n,-1){
m = n;
}
int find(int x){
if(parents.at(x) < 0){
return x;
}else{
parents.at(x) = find(parents.at(x));
return parents.at(x);
}
}
void unite(int x,int y){
x = find(x);
y = find(y);
if(x==y) return;
if(parents.at(x) > parents.at(x))swap(x,y);
parents.at(x) += parents.at(y);
parents.at(y) = x;
}
int size(int x){
return -parents.at(find(x));
}
bool same(int x,int y){
return find(x) ==find(y);
}
vector<int> members(int x){
int root = find(x);
vector<int> A;
for(int i=0;i<m;i++){
if(find(i) ==root ){
A.push_back(i);
}
}
return A;
}
};
int main(){
vector<edge> EG;
int n,m,k;
cin >> n >> m >>k;
vector<int> a(m),b(m);
vector<ll> c(m);
ll sum = 0;
rep(i,m){
cin >> a[i] >> b[i] >> c[i];
--a[i];--b[i];
sum += c[i];
EG.push_back(edge(c[i],a[i],b[i]));
}
Unionfind uf(n);
ll res = 0;
rep(i,k){
int e;
cin >> e;
--e;
uf.unite(a[e],b[e]);
res += c[e];
EG[e].cost = LINF;
}
sort(EG.begin(),EG.end());
for(edge eg:EG){
if(uf.same(eg.from,eg.to)) continue;
uf.unite(eg.from,eg.to);
res += eg.cost;
}
cout << sum - res << endl;
return 0;
}