結果

問題 No.748 yuki国のお財布事情
ユーザー kotamanegi
提出日時 2018-10-19 22:25:31
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 1,682 bytes
コンパイル時間 1,030 ms
コンパイル使用メモリ 114,032 KB
実行使用メモリ 5,324 KB
最終ジャッジ日時 2024-11-18 21:15:32
合計ジャッジ時間 3,134 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

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