結果

問題 No.748 yuki国のお財布事情
ユーザー startcppstartcpp
提出日時 2018-10-19 22:55:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,015 bytes
コンパイル時間 841 ms
コンパイル使用メモリ 72,904 KB
実行使用メモリ 9,760 KB
最終ジャッジ日時 2023-08-12 02:00:51
合計ジャッジ時間 3,498 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,360 KB
testcase_01 AC 3 ms
8,532 KB
testcase_02 AC 3 ms
8,280 KB
testcase_03 AC 3 ms
8,232 KB
testcase_04 AC 3 ms
8,232 KB
testcase_05 AC 3 ms
8,240 KB
testcase_06 AC 3 ms
8,232 KB
testcase_07 AC 3 ms
8,536 KB
testcase_08 AC 3 ms
8,344 KB
testcase_09 AC 3 ms
8,228 KB
testcase_10 AC 3 ms
8,296 KB
testcase_11 AC 3 ms
8,292 KB
testcase_12 AC 3 ms
8,304 KB
testcase_13 AC 16 ms
8,572 KB
testcase_14 AC 27 ms
8,816 KB
testcase_15 AC 19 ms
8,640 KB
testcase_16 AC 50 ms
9,200 KB
testcase_17 AC 98 ms
9,564 KB
testcase_18 AC 115 ms
9,604 KB
testcase_19 AC 129 ms
9,672 KB
testcase_20 AC 115 ms
9,512 KB
testcase_21 AC 108 ms
9,744 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 3 ms
8,248 KB
testcase_24 AC 3 ms
8,428 KB
testcase_25 AC 87 ms
9,724 KB
testcase_26 AC 107 ms
9,648 KB
testcase_27 AC 105 ms
9,664 KB
testcase_28 AC 89 ms
9,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
typedef tuple<int, int, int> T;

struct UF {
	int par[100000];
	UF() { int i; rep(i, 100000) par[i] = i; }
	int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); }
	void unit(int x, int y) { x = root(x); y = root(y); par[x] = y; }
	bool same(int x, int y) { return root(x) == root(y); }
};

int n, m, k;
int a[100000], b[100000], c[100000];
int e[100000];
T edges[100000];
UF uf;

signed main() {
	int i;
	
	cin >> n >> m >> k;
	rep(i, m) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; }
	rep(i, k) { cin >> e[i]; e[i]--; c[e[i]] = 0; }
	rep(i, m) { edges[i] = T(c[i], a[i], b[i]); }
	sort(edges, edges + m);
	
	int ans = 0;
	rep(i, m) {
		int cst = get<0>(edges[i]);
		int u = get<1>(edges[i]);
		int v = get<2>(edges[i]);
		if (uf.same(u, v)) {
			ans += cst;
		}
		else {
			uf.unit(u, v);
		}
	}
	cout << ans << endl;
	return 0;
}
0