結果

問題 No.748 yuki国のお財布事情
ユーザー kotamanegikotamanegi
提出日時 2018-10-19 22:25:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 1,682 bytes
コンパイル時間 1,006 ms
コンパイル使用メモリ 112,204 KB
実行使用メモリ 5,232 KB
最終ジャッジ日時 2023-08-12 01:23:44
合計ジャッジ時間 3,766 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 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,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 14 ms
4,376 KB
testcase_14 AC 26 ms
4,376 KB
testcase_15 AC 18 ms
4,384 KB
testcase_16 AC 49 ms
4,380 KB
testcase_17 AC 98 ms
4,844 KB
testcase_18 AC 117 ms
4,796 KB
testcase_19 AC 133 ms
5,092 KB
testcase_20 AC 121 ms
4,860 KB
testcase_21 AC 112 ms
5,232 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 88 ms
4,792 KB
testcase_26 AC 108 ms
5,052 KB
testcase_27 AC 105 ms
5,104 KB
testcase_28 AC 90 ms
4,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long union_find[200000] = {};
int union_search(int k) {
	if (union_find[k] == k) return k;
	return union_find[k] = union_search(union_find[k]);
}
int union_merge(int a, int b) {
	a = union_search(a);
	b = union_search(b);
	union_find[a] = b;
	return 0;
}
int main() {
	int n, m, k;
	cin >> n >> m >> k;
	vector<tuple<int, int, int>> edges;
	long long ans = 0;
	REP(i, m) {
		long long a, b, c;
		cin >> a >> b >> c;
		ans += c;
		edges.push_back(make_tuple(c, a, b));
	}
	REP(i, n) {
		union_find[i] = i;
	}
	REP(i, k) {
		int a;
		cin >> a;
		a--;
		ans -= get<0>(edges[a]);
		union_merge(get<1>(edges[a]), get<2>(edges[a]));
	}
	sort(edges.begin(), edges.end());
	REP(i, m) {
		int a = get<1>(edges[i]);
		int b = get<2>(edges[i]);
		if (union_search(a) != union_search(b)) {
			union_merge(a, b);
			ans -= get<0>(edges[i]);
		}
	}
	cout << ans << endl;
	return 0;
}
0