結果

問題 No.2427 Tree Distance Two
ユーザー pengin_2000pengin_2000
提出日時 2023-08-18 21:36:29
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 517 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 29,180 KB
実行使用メモリ 6,560 KB
最終ジャッジ日時 2023-08-18 21:36:38
合計ジャッジ時間 4,163 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 89 ms
6,544 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 91 ms
6,488 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 90 ms
6,428 KB
testcase_08 AC 91 ms
6,536 KB
testcase_09 AC 91 ms
6,364 KB
testcase_10 AC 89 ms
6,488 KB
testcase_11 AC 91 ms
6,440 KB
testcase_12 AC 91 ms
6,560 KB
testcase_13 AC 93 ms
6,544 KB
testcase_14 AC 85 ms
6,528 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 23 ms
4,472 KB
testcase_26 AC 56 ms
5,472 KB
testcase_27 AC 39 ms
4,852 KB
testcase_28 AC 83 ms
6,208 KB
testcase_29 AC 73 ms
5,996 KB
testcase_30 AC 55 ms
5,380 KB
testcase_31 AC 34 ms
4,696 KB
testcase_32 AC 53 ms
5,336 KB
testcase_33 AC 47 ms
5,156 KB
testcase_34 AC 14 ms
4,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