結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | ikd |
提出日時 | 2018-07-18 00:50:14 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 130 ms / 2,000 ms |
コード長 | 1,230 bytes |
コンパイル時間 | 823 ms |
コンパイル使用メモリ | 81,200 KB |
実行使用メモリ | 5,352 KB |
最終ジャッジ日時 | 2023-09-18 02:22:04 |
合計ジャッジ時間 | 3,262 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 1 ms
4,376 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | AC | 2 ms
4,376 KB |
testcase_11 | AC | 1 ms
4,376 KB |
testcase_12 | AC | 2 ms
4,380 KB |
testcase_13 | AC | 14 ms
4,380 KB |
testcase_14 | AC | 25 ms
4,376 KB |
testcase_15 | AC | 17 ms
4,376 KB |
testcase_16 | AC | 49 ms
4,380 KB |
testcase_17 | AC | 98 ms
5,352 KB |
testcase_18 | AC | 115 ms
5,248 KB |
testcase_19 | AC | 130 ms
5,048 KB |
testcase_20 | AC | 116 ms
5,196 KB |
testcase_21 | AC | 107 ms
5,076 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 | 86 ms
5,016 KB |
testcase_26 | AC | 104 ms
5,064 KB |
testcase_27 | AC | 103 ms
5,248 KB |
testcase_28 | AC | 90 ms
5,252 KB |
ソースコード
#include<iostream> #include<vector> #include<algorithm> #include<numeric> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) struct UnionFind{ vector<int> par; UnionFind(int n){ par.resize(n); rep(i, n) par[i]=i; } int find(int i){ return par[i]==i ? par[i] : (par[i]=find(par[i])); } void unite(int i, int j){ par[find(i)]=find(j); } bool same(int i, int j){ return find(i)==find(j); } }; using i64=long long; struct Edge{ int u, v; i64 cost; Edge(int u, int v, i64 c):u(u), v(v), cost(c){}; }; int main(){ int n, m, k; cin>> n>> m>> k; vector<Edge> edges; rep(_, m){ int a, b; i64 c; cin>> a>> b>> c; edges.push_back(Edge{a-1, b-1, c}); } i64 sum=0; UnionFind uf(n); rep(_, k){ int i; cin>> i; i--; uf.unite(edges[i].u, edges[i].v); sum+=edges[i].cost; } sort(edges.begin(), edges.end(), [&](const Edge &l, const Edge &r){ return l.cost<r.cost; }); for(auto e: edges){ if(uf.same(e.u, e.v)==false){ uf.unite(e.u, e.v); sum+=e.cost; } } auto tot=accumulate(edges.begin(), edges.end(), 0LL, [&](i64 res, const Edge &e){ return res+e.cost; }); cout<< tot-sum<< endl; return 0; }