結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | 夕叢霧香(ゆうむらきりか) |
提出日時 | 2018-10-19 21:49:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 134 ms / 2,000 ms |
コード長 | 950 bytes |
コンパイル時間 | 919 ms |
コンパイル使用メモリ | 83,984 KB |
最終ジャッジ日時 | 2025-01-06 14:38:12 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include<algorithm> #include<iostream> #include<vector> using namespace std; typedef long long lint; typedef vector<int>vi; typedef pair<int,int>pii; typedef pair<lint,pii>edge; #define rep(i,n)for(int i=0;i<(int)(n);++i) const int N=110000; int par[N]; int root(int x){ if(x==par[x])return x; return par[x]=root(par[x]); } void unify(int x,int y){ x=root(x),y=root(y); par[x]=y; } int main(){ rep(i,N)par[i]=i; int n,m,k;cin>>n>>m>>k; vector<edge>es; lint sum=0; rep(i,m){ int a,b,c;cin>>a>>b>>c; es.push_back(edge(c,pii(a-1,b-1))); sum+=c; } vi e(k); lint ans=0; rep(i,k){ cin>>e[i],e[i]--; ans+=es[e[i]].first; unify(es[e[i]].second.first,es[e[i]].second.second); } sort(es.begin(),es.end()); rep(i,es.size()){ lint c=es[i].first; int a=es[i].second.first; int b=es[i].second.second; if(root(a)!=root(b)){ unify(a,b); ans+=c; } } cout<<sum-ans<<endl; }