結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | とばり |
提出日時 | 2018-10-19 22:15:04 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 47 ms / 2,000 ms |
コード長 | 1,783 bytes |
コンパイル時間 | 1,670 ms |
コンパイル使用メモリ | 172,756 KB |
実行使用メモリ | 4,952 KB |
最終ジャッジ日時 | 2023-08-12 01:13:27 |
合計ジャッジ時間 | 3,488 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | AC | 1 ms
4,380 KB |
testcase_11 | AC | 1 ms
4,380 KB |
testcase_12 | AC | 1 ms
4,380 KB |
testcase_13 | AC | 6 ms
4,376 KB |
testcase_14 | AC | 10 ms
4,376 KB |
testcase_15 | AC | 8 ms
4,384 KB |
testcase_16 | AC | 19 ms
4,380 KB |
testcase_17 | AC | 36 ms
4,556 KB |
testcase_18 | AC | 43 ms
4,824 KB |
testcase_19 | AC | 47 ms
4,924 KB |
testcase_20 | AC | 42 ms
4,952 KB |
testcase_21 | AC | 40 ms
4,952 KB |
testcase_22 | AC | 2 ms
4,380 KB |
testcase_23 | AC | 2 ms
4,376 KB |
testcase_24 | AC | 2 ms
4,380 KB |
testcase_25 | AC | 34 ms
4,560 KB |
testcase_26 | AC | 40 ms
4,896 KB |
testcase_27 | AC | 39 ms
4,872 KB |
testcase_28 | AC | 31 ms
4,416 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; }