結果

問題 No.748 yuki国のお財布事情
ユーザー ats5515ats5515
提出日時 2018-10-19 21:46:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,315 bytes
コンパイル時間 2,995 ms
コンパイル使用メモリ 85,244 KB
実行使用メモリ 7,396 KB
最終ジャッジ日時 2023-08-12 00:45:04
合計ジャッジ時間 3,241 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,388 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 12 ms
4,380 KB
testcase_15 AC 9 ms
4,380 KB
testcase_16 AC 20 ms
4,908 KB
testcase_17 AC 43 ms
6,436 KB
testcase_18 AC 47 ms
6,380 KB
testcase_19 AC 48 ms
6,140 KB
testcase_20 AC 43 ms
6,264 KB
testcase_21 AC 47 ms
6,244 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 42 ms
6,388 KB
testcase_26 AC 47 ms
7,396 KB
testcase_27 AC 47 ms
6,816 KB
testcase_28 AC 34 ms
6,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};
struct E {
	int a, b, c;
	bool operator<(const E &right) const {
		return c < right.c;
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, K;
	cin >> N >> M >> K;
	int a, b, c;
	vector<E> es;
	int sum = 0;
	for (int i = 0; i < M; i++) {
		cin >> a >> b >> c;
		sum += c;
		a--; b--;
		es.push_back(E{ a,b,c });
	}
	UnionFind uf(N);
	for (int i = 0; i < K; i++) {
		cin >> a;
		a--;
		sum -= es[a].c;
		es[a].c = 0;
	}
	sort(es.begin(), es.end());
	for (int i = 0; i < es.size(); i++) {
		if (!uf.findSet(es[i].a, es[i].b)) {
			uf.unionSet(es[i].a, es[i].b);
			sum -= es[i].c;
		}
	}
	cout << sum << endl;
}
0