結果

問題 No.748 yuki国のお財布事情
ユーザー startcppstartcpp
提出日時 2018-10-19 22:55:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,015 bytes
コンパイル時間 950 ms
コンパイル使用メモリ 70,612 KB
実行使用メモリ 9,472 KB
最終ジャッジ日時 2024-04-29 16:42:59
合計ジャッジ時間 3,287 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 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 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 16 ms
5,376 KB
testcase_14 AC 29 ms
5,376 KB
testcase_15 AC 20 ms
5,376 KB
testcase_16 AC 53 ms
6,272 KB
testcase_17 AC 105 ms
8,576 KB
testcase_18 AC 125 ms
9,216 KB
testcase_19 AC 139 ms
9,472 KB
testcase_20 AC 123 ms
8,832 KB
testcase_21 AC 116 ms
8,832 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 95 ms
8,832 KB
testcase_26 AC 115 ms
8,960 KB
testcase_27 AC 113 ms
8,960 KB
testcase_28 AC 97 ms
7,936 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