結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | とばり |
提出日時 | 2018-10-19 22:15:04 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 1,783 bytes |
コンパイル時間 | 1,768 ms |
コンパイル使用メモリ | 175,028 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-04-29 16:02:41 |
合計ジャッジ時間 | 3,305 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 7 ms
5,376 KB |
testcase_14 | AC | 11 ms
5,376 KB |
testcase_15 | AC | 8 ms
5,376 KB |
testcase_16 | AC | 20 ms
5,376 KB |
testcase_17 | AC | 39 ms
5,376 KB |
testcase_18 | AC | 46 ms
5,376 KB |
testcase_19 | AC | 51 ms
5,376 KB |
testcase_20 | AC | 45 ms
5,376 KB |
testcase_21 | AC | 45 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 37 ms
5,376 KB |
testcase_26 | AC | 43 ms
5,376 KB |
testcase_27 | AC | 42 ms
5,376 KB |
testcase_28 | AC | 35 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define repeat(i, x) for (int64_t i = 0; (i) < (int64_t)(x); (i)++) // tubo28 is god struct uf_tree { std::vector<int> parent; int __size; uf_tree(int size_) : parent(size_, -1), __size(size_) {} void unite(int x, int y) { if ((x = find(x)) != (y = find(y))) { if (parent[y] < parent[x]) std::swap(x, y); parent[x] += parent[y]; parent[y] = x; __size--; } } bool is_same(int x, int y) { return find(x) == find(y); } int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); } int size(int x) { return -parent[find(x)]; } int size() { return __size; } }; namespace TaskE { struct Edge { int u, v; int64_t cost; bool operator<(const Edge& e) const { return cost < e.cost; } }; int n_, m_, k_; void solve() { cin >> n_ >> m_ >> k_; int64_t sum = 0; vector<Edge> edges(m_); repeat (i, m_) { cin >> edges[i].u >> edges[i].v >> edges[i].cost; edges[i].u--; edges[i].v--; sum += edges[i].cost; } uf_tree uf(n_); int64_t cost = 0; repeat (i, k_) { int e; cin >> e; e--; uf.unite(edges[e].u, edges[e].v); cost += edges[e].cost; } sort(edges.begin(), edges.end()); for (auto& e : edges) { if (!uf.is_same(e.u, e.v)) { uf.unite(e.u, e.v); cost += e.cost; } } cout << sum - cost << endl; } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); TaskE::solve(); return 0; }