結果
| 問題 |
No.748 yuki国のお財布事情
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2018-10-19 22:14:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 163 ms / 2,000 ms |
| コード長 | 1,732 bytes |
| コンパイル時間 | 2,621 ms |
| コンパイル使用メモリ | 206,984 KB |
| 最終ジャッジ日時 | 2025-01-06 14:40:39 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T>
struct Kruskal{
struct edge{
Int from,to;
T cost;
Int used;
edge(){}
edge(Int from,Int to,T cost):
from(from),to(to),cost(cost),used(0){}
bool operator<(const edge& e) const{
return cost<e.cost;
}
};
Int n;
vector<Int> p,r;
vector<edge> edges;
Kruskal(){}
Kruskal(Int n):n(n){}
void init(Int n){
r.assign(n,1);
p.resize(n);
iota(p.begin(),p.end(),0);
}
Int find(Int x){
return (x==p[x]?x:p[x]=find(p[x]));
}
bool same(Int x,Int y){
return find(x)==find(y);
}
void unite(Int x,Int y){
x=find(x);y=find(y);
if(x==y) return;
if(r[x]<r[y]) swap(x,y);
r[x]+=r[y];
p[y]=x;
}
void add_edge(Int u,Int v,T c){
edges.emplace_back(u,v,c);
}
Int build(){
sort(edges.begin(),edges.end());
init(n);
Int res=0;
for(auto &e:edges){
if(!e.cost.first||!same(e.from,e.to)){
res+=e.cost.second;
unite(e.from,e.to);
e.used=1;
}
}
return res;
}
};
//INSERT ABOVE HERE
signed main(){
Int n,m,k;
cin>>n>>m>>k;
vector<Int> a(m),b(m),c(m);
Int sum=0;
for(Int i=0;i<m;i++){
cin>>a[i]>>b[i]>>c[i];
a[i]--;b[i]--;
sum+=c[i];
}
vector<Int> e(k);
for(Int i=0;i<k;i++) cin>>e[i];
vector<Int> u(m);
for(Int i=0;i<k;i++) u[--e[i]]=1;
using P = pair<Int, Int>;
Kruskal<P> G(n);
for(Int i=0;i<m;i++)
G.add_edge(a[i],b[i],P(!u[i],c[i]));
Int res=G.build();
cout<<sum-res<<endl;
return 0;
}
beet