結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | mtsd |
提出日時 | 2018-10-19 21:42:17 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 135 ms / 2,000 ms |
コード長 | 1,759 bytes |
コンパイル時間 | 969 ms |
コンパイル使用メモリ | 90,348 KB |
実行使用メモリ | 7,268 KB |
最終ジャッジ日時 | 2023-08-12 00:30:42 |
合計ジャッジ時間 | 3,925 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 1 ms
4,376 KB |
testcase_11 | AC | 1 ms
4,376 KB |
testcase_12 | AC | 2 ms
4,376 KB |
testcase_13 | AC | 16 ms
4,376 KB |
testcase_14 | AC | 26 ms
4,376 KB |
testcase_15 | AC | 18 ms
4,376 KB |
testcase_16 | AC | 50 ms
4,724 KB |
testcase_17 | AC | 101 ms
6,116 KB |
testcase_18 | AC | 117 ms
6,420 KB |
testcase_19 | AC | 135 ms
6,408 KB |
testcase_20 | AC | 120 ms
6,292 KB |
testcase_21 | AC | 123 ms
6,524 KB |
testcase_22 | AC | 1 ms
4,376 KB |
testcase_23 | AC | 1 ms
4,376 KB |
testcase_24 | AC | 2 ms
4,380 KB |
testcase_25 | AC | 91 ms
6,480 KB |
testcase_26 | AC | 111 ms
6,920 KB |
testcase_27 | AC | 106 ms
7,268 KB |
testcase_28 | AC | 90 ms
6,224 KB |
ソースコード
#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; }