結果

問題 No.748 yuki国のお財布事情
ユーザー finefine
提出日時 2018-10-20 01:27:47
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,854 bytes
コンパイル時間 2,029 ms
コンパイル使用メモリ 176,416 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-19 00:35:11
合計ジャッジ時間 3,779 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct UnionFind {
//()
//xdata[x]-data[x]x
vector<int> data;
UnionFind(int sz) : data(sz, -1) {}
bool unite(int x, int y) {
x = find(x);
y = find(y);
bool is_union = (x != y);
if (is_union) {
if (data[x] > data[y]) swap(x, y);
data[x] += data[y];
data[y] = x;
}
return is_union;
}
int find(int x) {
if (data[x] < 0) { //x
return x;
} else {
data[x] = find(data[x]); //data[x]x
return data[x];
}
}
bool same(int x, int y) {
return find(x) == find(y);
}
int size(int x) {
return -data[find(x)];
}
};
struct Edge {
int u, v;
ll cost;
bool operator<(const Edge& e) const {
return cost < e.cost;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m, k;
cin >> n >> m >> k;
vector<Edge> es;
ll ans = 0;
for (int i = 0; i < m; i++) {
int a, b;
ll c;
cin >> a >> b >> c;
a--; b--;
es.push_back({a, b, c});
ans += c;
}
UnionFind uf(n);
for (int i = 0; i < k; i++) {
int e;
cin >> e;
e--;
uf.unite(es[e].u, es[e].v);
ans -= es[e].cost;
}
sort(es.begin(), es.end());
for (Edge& e : es) {
if (!uf.same(e.u, e.v)) {
uf.unite(e.u, e.v);
ans -= e.cost;
}
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0