結果

問題 No.2427 Tree Distance Two
ユーザー pengin_2000pengin_2000
提出日時 2023-08-18 21:36:29
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 517 bytes
コンパイル時間 1,117 ms
コンパイル使用メモリ 29,568 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-05-06 03:31:09
合計ジャッジ時間 4,712 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 88 ms
6,528 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 87 ms
6,528 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 85 ms
6,528 KB
testcase_08 AC 87 ms
6,528 KB
testcase_09 AC 84 ms
6,528 KB
testcase_10 AC 82 ms
6,528 KB
testcase_11 AC 86 ms
6,528 KB
testcase_12 AC 84 ms
6,528 KB
testcase_13 AC 85 ms
6,528 KB
testcase_14 AC 79 ms
6,400 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 21 ms
5,376 KB
testcase_26 AC 52 ms
5,376 KB
testcase_27 AC 36 ms
5,376 KB
testcase_28 AC 77 ms
6,144 KB
testcase_29 AC 70 ms
5,632 KB
testcase_30 AC 51 ms
5,376 KB
testcase_31 AC 34 ms
5,376 KB
testcase_32 AC 52 ms
5,376 KB
testcase_33 AC 44 ms
5,376 KB
testcase_34 AC 16 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
int u[300005], v[300005];
int deg[300005];
int ans[300005];
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int m = n - 1;
	for (i = 0; i < m; i++)
	{
		scanf("%d %d", &u[i], &v[i]);
		u[i]--;
		v[i]--;
	}
	for (i = 0; i < n; i++)
		deg[i] = 0;
	for (i = 0; i < m; i++)
	{
		deg[u[i]]++;
		deg[v[i]]++;
	}
	for (i = 0; i < n; i++)
		ans[i] = 0;
	for (i = 0; i < m; i++)
	{
		ans[u[i]] += deg[v[i]] - 1;
		ans[v[i]] += deg[u[i]] - 1;
	}
	for (i = 0; i < n; i++)
		printf("%d\n", ans[i]);
	return 0;
}
0