結果
| 問題 |
No.748 yuki国のお財布事情
|
| コンテスト | |
| ユーザー |
mtsd
|
| 提出日時 | 2018-10-19 21:42:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 138 ms / 2,000 ms |
| コード長 | 1,759 bytes |
| コンパイル時間 | 930 ms |
| コンパイル使用メモリ | 94,676 KB |
| 実行使用メモリ | 6,864 KB |
| 最終ジャッジ日時 | 2024-11-18 20:18:13 |
| 合計ジャッジ時間 | 3,218 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
class UF {
private:
int sz; vector<int> par,nrank,size;
public:
UF(){}
UF(int node_size){ sz = node_size; par.resize(sz),nrank.resize(sz),size.resize(sz);
rep(i,sz){ par[i] = i; nrank[i] = 0; size[i] = 1;} }
int find(int x){ if(par[x] == x){ return x; }else{ return par[x] = find(par[x]); } }
void unite(int x,int y)
{ x = find(x),y = find(y); if(x == y) return; if(nrank[x] < nrank[y]) swap(x,y);
par[y] = x; size[x] += size[y]; if(nrank[x] == nrank[y]) nrank[x]++; }
int query(int x){ x = find(x); return size[x]; }
bool same(int x,int y){ return find(x) == find(y); }
};
int main(){
ll n,m,k;
cin >> n >> m >> k;
vector<pair<ll,pair<ll,ll> > > v;
for(int i=0;i<m;i++){
ll a,b,c;
cin >> a >> b >> c;
a--;
b--;
v.PB(MP(c,MP(a,b)));
}
UF uf(n);
ll ans = 0;
for(int i=0;i<k;i++){
int e;
cin >> e;
e--;
ans -= v[e].first;
uf.unite(v[e].second.first,v[e].second.second);
}
sort(v.begin(),v.end());
for(int i=0;i<m;i++){
if(uf.same(v[i].second.first,v[i].second.second)){
ans += v[i].first;
}else{
uf.unite(v[i].second.first,v[i].second.second);
}
}
cout << ans << endl;
return 0;
}
mtsd