結果

問題 No.748 yuki国のお財布事情
ユーザー kotatsugamekotatsugame
提出日時 2018-10-19 23:32:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,036 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 80,956 KB
実行使用メモリ 6,204 KB
最終ジャッジ日時 2023-08-12 02:29:50
合計ジャッジ時間 3,498 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 15 ms
4,376 KB
testcase_14 AC 26 ms
4,376 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 48 ms
4,376 KB
testcase_17 AC 96 ms
5,432 KB
testcase_18 AC 113 ms
5,904 KB
testcase_19 AC 125 ms
6,096 KB
testcase_20 AC 112 ms
6,028 KB
testcase_21 AC 107 ms
6,204 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 89 ms
5,520 KB
testcase_26 AC 106 ms
6,172 KB
testcase_27 AC 103 ms
6,164 KB
testcase_28 AC 86 ms
5,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:40:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   40 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,k;
int a[1<<17],b[1<<17],c[1<<17];
long sum;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,0)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a)
	{
		return parent[a]!=a?parent[a]=find(parent[a]):a;
	}
	bool same(int a,int b)
	{
		return find(a)==find(b);
	}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
		}
		else
		{
			parent[b]=a;
			if(rank[a]==rank[b])rank[a]++;
		}
		return true;
	}
};
main()
{
	cin>>n>>m>>k;
	vector<pair<int,pair<int,int> > >G;
	for(int i=0;i<m;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
		sum+=c[i];
		G.push_back(make_pair(c[i],make_pair(a[i],b[i])));
	}
	UF uf(n+1);
	for(int i=0;i<k;i++)
	{
		int e;cin>>e;
		e--;
		sum-=c[e];
		uf.unite(a[e],b[e]);
	}
	sort(G.begin(),G.end());
	for(int i=0;i<m;i++)
	{
		if(uf.unite(G[i].second.first,G[i].second.second))sum-=G[i].first;
	}
	cout<<sum<<endl;
}
0