結果

問題 No.748 yuki国のお財布事情
ユーザー cielciel
提出日時 2018-10-23 09:57:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 683 bytes
コンパイル時間 428 ms
コンパイル使用メモリ 46,760 KB
実行使用メモリ 4,936 KB
最終ジャッジ日時 2023-08-12 06:15:35
合計ジャッジ時間 2,427 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 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 1 ms
4,376 KB
testcase_13 AC 7 ms
4,380 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 8 ms
4,376 KB
testcase_16 AC 20 ms
4,376 KB
testcase_17 AC 41 ms
4,592 KB
testcase_18 AC 48 ms
4,808 KB
testcase_19 AC 53 ms
4,912 KB
testcase_20 AC 46 ms
4,732 KB
testcase_21 AC 46 ms
4,828 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 37 ms
4,576 KB
testcase_26 AC 45 ms
4,936 KB
testcase_27 AC 44 ms
4,860 KB
testcase_28 AC 34 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//kruskal tree
#include <cstdio>
#include <algorithm>
using namespace std;
#define M 99999
int parent[M],a[M],b[M];
pair<int,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	long long s=0;
	int i,n,m,k,x;
	scanf("%d%d%d",&n,&m,&k);
	for(i=0;i<m;i++)scanf("%d%d%d",a+i,b+i,&node[i].first),a[i]--,b[i]--,node[i].second=i;
	for(i=0;i<k;i++)scanf("%d",&x),x--,unite(a[x],b[x]),node[x].first=0;
	sort(node,node+m);
	for(i=0;i<n;i++)parent[i]=i;
	for(i=0;i<m;i++)if(!unite(a[node[i].second],b[node[i].second]))s+=node[i].first;
	printf("%lld\n",s);
}
0