結果

問題 No.1390 Get together
ユーザー kotatsugamekotatsugame
提出日時 2021-02-12 21:34:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 903 bytes
コンパイル時間 1,016 ms
コンパイル使用メモリ 72,968 KB
実行使用メモリ 13,504 KB
最終ジャッジ日時 2023-09-27 03:07:40
合計ジャッジ時間 4,664 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 3 ms
4,384 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 4 ms
4,384 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 108 ms
10,364 KB
testcase_17 AC 149 ms
13,216 KB
testcase_18 AC 117 ms
10,584 KB
testcase_19 AC 170 ms
13,368 KB
testcase_20 AC 154 ms
13,504 KB
testcase_21 AC 155 ms
13,248 KB
testcase_22 AC 134 ms
12,216 KB
testcase_23 AC 139 ms
12,264 KB
testcase_24 AC 140 ms
12,356 KB
testcase_25 AC 152 ms
13,236 KB
testcase_26 AC 155 ms
13,308 KB
testcase_27 AC 154 ms
13,336 KB
testcase_28 AC 154 ms
13,480 KB
testcase_29 AC 158 ms
13,304 KB
testcase_30 AC 155 ms
13,160 KB
testcase_31 AC 155 ms
13,212 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
a.cpp:6:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]

ソースコード

diff #

#line 1 "a.cpp"
#include<iostream>
#include<vector>
using namespace std;
#line 2 "/home/kotatsugame/library/datastructure/UF.cpp"
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		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;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
#line 5 "a.cpp"
int N,M;
main()
{
	cin>>N>>M;
	UF uf(M);
	vector<vector<int> >G(N);
	for(int i=0;i<N;i++)
	{
		int b,c;cin>>b>>c;
		G[c-1].push_back(b-1);
	}
	int ans=0;
	for(vector<int>&v:G)
	{
		for(int i=1;i<v.size();i++)ans+=uf.unite(v[0],v[i]);
	}
	cout<<ans<<endl;
}
0