結果

問題 No.1639 最小通信路
ユーザー pengin_2000pengin_2000
提出日時 2021-08-06 22:18:56
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 498 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 30,464 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-17 02:22:14
合計ジャッジ時間 1,360 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
int p[102], cnt[102];
int root(int n)
{
	if (n != p[n])
		p[n] = root(p[n]);
	return p[n];
}
void uni(int x, int y)
{
	x = root(x);
	y = root(y);
	if (x != y)
		cnt[x] += cnt[y];
	p[y] = x;
	return;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	for (i = 0; i < n; i++)
	{
		p[i] = i;
		cnt[i] = 1;
	}
	int a, b;
	char c[102];
	for (;;)
	{
		scanf("%d %d %s", &a, &b, c);
		uni(a - 1, b - 1);
		if (cnt[root(a - 1)] == n)
		{
			printf("%s\n", c);
			break;
		}
	}
	return 0;
}
0