結果

問題 No.1817 Reversed Edges
ユーザー publfl2publfl2
提出日時 2022-01-21 21:34:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 48,536 KB
実行使用メモリ 16,640 KB
最終ジャッジ日時 2023-08-17 05:08:39
合計ジャッジ時間 3,124 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,312 KB
testcase_01 AC 3 ms
5,356 KB
testcase_02 AC 3 ms
5,320 KB
testcase_03 AC 3 ms
5,308 KB
testcase_04 AC 3 ms
5,316 KB
testcase_05 AC 3 ms
5,380 KB
testcase_06 AC 3 ms
5,316 KB
testcase_07 AC 58 ms
8,552 KB
testcase_08 AC 26 ms
6,860 KB
testcase_09 AC 51 ms
8,316 KB
testcase_10 AC 28 ms
7,072 KB
testcase_11 AC 36 ms
7,632 KB
testcase_12 AC 65 ms
8,940 KB
testcase_13 AC 65 ms
8,916 KB
testcase_14 AC 68 ms
8,940 KB
testcase_15 AC 64 ms
8,928 KB
testcase_16 AC 64 ms
8,936 KB
testcase_17 AC 66 ms
8,984 KB
testcase_18 AC 65 ms
8,940 KB
testcase_19 AC 65 ms
8,992 KB
testcase_20 AC 64 ms
8,912 KB
testcase_21 AC 63 ms
8,988 KB
testcase_22 AC 36 ms
8,888 KB
testcase_23 AC 35 ms
8,896 KB
testcase_24 AC 49 ms
16,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

std::vector<int> V[100010];
int init(int k, int prev)
{
	int ans = 0;
	for(int i=0;i<V[k].size();i++)
	{
		if(V[k][i]==prev) continue;
		ans += init(V[k][i],k);
		if(V[k][i]<k) ans++;
	}
	return ans;
}

int ans[100010];
void func(int k, int prev, int val)
{
	ans[k] = val;
	for(int i=0;i<V[k].size();i++)
	{
		if(V[k][i]==prev) continue;
		if(V[k][i]<k) func(V[k][i],k,val-1);
		else func(V[k][i],k,val+1);
	}
}

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