結果

問題 No.1390 Get together
ユーザー publflpublfl
提出日時 2021-02-12 21:28:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 568 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 49,136 KB
実行使用メモリ 23,464 KB
最終ジャッジ日時 2023-09-27 02:52:19
合計ジャッジ時間 4,611 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,736 KB
testcase_01 AC 5 ms
13,736 KB
testcase_02 AC 5 ms
13,696 KB
testcase_03 AC 7 ms
13,960 KB
testcase_04 AC 6 ms
13,860 KB
testcase_05 AC 7 ms
13,888 KB
testcase_06 AC 6 ms
13,864 KB
testcase_07 AC 6 ms
13,860 KB
testcase_08 AC 6 ms
13,864 KB
testcase_09 AC 7 ms
13,972 KB
testcase_10 AC 5 ms
13,700 KB
testcase_11 AC 5 ms
13,752 KB
testcase_12 AC 5 ms
13,764 KB
testcase_13 AC 5 ms
13,684 KB
testcase_14 AC 5 ms
13,700 KB
testcase_15 AC 5 ms
13,748 KB
testcase_16 AC 84 ms
19,140 KB
testcase_17 AC 89 ms
19,948 KB
testcase_18 AC 86 ms
21,300 KB
testcase_19 AC 165 ms
23,292 KB
testcase_20 AC 138 ms
22,820 KB
testcase_21 AC 141 ms
22,844 KB
testcase_22 AC 130 ms
22,432 KB
testcase_23 AC 127 ms
22,408 KB
testcase_24 AC 125 ms
22,440 KB
testcase_25 AC 161 ms
23,464 KB
testcase_26 AC 161 ms
23,384 KB
testcase_27 AC 161 ms
23,460 KB
testcase_28 AC 159 ms
23,376 KB
testcase_29 AC 161 ms
23,396 KB
testcase_30 AC 160 ms
23,460 KB
testcase_31 AC 159 ms
23,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>

int x[400010];
std::vector<int> V[400010];
int check[400010];

int func(int k)
{
	if(check[k]) return 0;
	check[k] = 1;
	int ans = x[k];
	for(int i=0;i<V[k].size();i++) ans += func(V[k][i]);
	return ans;
}

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=a;i++)
	{
		int c,d;
		scanf("%d%d",&c,&d);
		V[d].push_back(c+a);
		V[c+a].push_back(d);
	}
	for(int i=a+1;i<=a+b;i++) x[i] = 1;
	int ans = 0;
	for(int i=a+1;i<=a+b;i++)
	{
		if(check[i]==0)
		{
			int C = func(i);
			ans += (C-1);
		}
	}
	printf("%d\n",ans);
}
0