結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー kriiikriii
提出日時 2018-12-16 00:35:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 740 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 49,204 KB
実行使用メモリ 10,292 KB
最終ジャッジ日時 2023-10-25 21:57:16
合計ジャッジ時間 2,458 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,616 KB
testcase_01 AC 2 ms
5,616 KB
testcase_02 AC 2 ms
5,616 KB
testcase_03 AC 2 ms
5,652 KB
testcase_04 AC 2 ms
5,656 KB
testcase_05 AC 2 ms
5,648 KB
testcase_06 AC 2 ms
5,640 KB
testcase_07 AC 31 ms
8,160 KB
testcase_08 AC 17 ms
6,984 KB
testcase_09 AC 20 ms
7,244 KB
testcase_10 AC 15 ms
6,872 KB
testcase_11 AC 48 ms
9,404 KB
testcase_12 AC 48 ms
9,424 KB
testcase_13 AC 47 ms
9,336 KB
testcase_14 AC 46 ms
9,320 KB
testcase_15 AC 49 ms
9,524 KB
testcase_16 AC 48 ms
9,544 KB
testcase_17 AC 51 ms
9,620 KB
testcase_18 AC 43 ms
10,292 KB
testcase_19 AC 40 ms
10,052 KB
testcase_20 AC 44 ms
10,036 KB
testcase_21 AC 41 ms
9,756 KB
20evil_special_uni1.txt AC 48 ms
9,736 KB
20evil_special_uni2.txt AC 45 ms
9,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
using namespace std;

vector<int> G[100100];
int N,D[100100],V[100100];

void go(int x, int l)
{
	D[x] = 1;
	for (int y : G[x]) if (y != l){
		go(y,x);
		if (D[y] > 0) D[x] -= D[y];
	}
}

void go2(int x, int l)
{
	for (int y : G[x]) if (y != l){
		int v = D[x];
		if (D[y] > 0) v += D[y];
		if (V[x] > 0) v -= V[x];
		V[y] = v;
		go2(y,x);
	}
}

int main()
{
	scanf ("%d",&N);
	for (int i=1;i<N;i++){
		int x,y; scanf ("%d %d",&x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}

	go(1,0);
	go2(1,0);
	vector<int> ans;
	for (int i=1;i<=N;i++){
		int v = D[i];
		if (V[i] > 0) v -= V[i];
		if (v > 0) ans.push_back(i);
	}
	printf ("%d\n",ans.size());
	for (auto x : ans) printf ("%d\n",x);

	return 0;
}
0