結果

問題 No.806 木を道に
ユーザー kotatsugamekotatsugame
提出日時 2019-04-20 00:38:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 484 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 72,152 KB
実行使用メモリ 14,224 KB
最終ジャッジ日時 2023-10-24 17:14:11
合計ジャッジ時間 4,053 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,728 KB
testcase_01 AC 3 ms
6,728 KB
testcase_02 AC 3 ms
6,732 KB
testcase_03 AC 3 ms
6,732 KB
testcase_04 AC 3 ms
6,728 KB
testcase_05 AC 3 ms
6,732 KB
testcase_06 AC 3 ms
6,732 KB
testcase_07 AC 3 ms
6,728 KB
testcase_08 AC 3 ms
6,728 KB
testcase_09 AC 3 ms
6,732 KB
testcase_10 AC 18 ms
7,440 KB
testcase_11 AC 16 ms
7,364 KB
testcase_12 AC 65 ms
9,448 KB
testcase_13 AC 47 ms
8,700 KB
testcase_14 AC 61 ms
9,304 KB
testcase_15 AC 65 ms
9,492 KB
testcase_16 AC 24 ms
7,728 KB
testcase_17 AC 56 ms
9,112 KB
testcase_18 AC 7 ms
6,992 KB
testcase_19 AC 18 ms
7,476 KB
testcase_20 AC 57 ms
9,112 KB
testcase_21 AC 32 ms
8,076 KB
testcase_22 AC 75 ms
9,940 KB
testcase_23 AC 74 ms
9,924 KB
testcase_24 AC 39 ms
11,668 KB
testcase_25 AC 59 ms
14,224 KB
testcase_26 AC 20 ms
7,664 KB
testcase_27 AC 64 ms
9,892 KB
testcase_28 AC 4 ms
6,832 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   17 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N;
vector<int>G[1<<17];
int dfs(int u,int p)
{
	int ret=G[u].size()>2?G[u].size()-2:0;
	for(int i=0;i<G[u].size();i++)
	{
		if(G[u][i]==p)continue;
		ret+=dfs(G[u][i],u);
	}
	return ret;
}
main()
{
	cin>>N;
	for(int i=1;i<N;i++)
	{
		int a,b;cin>>a>>b;
		G[a-1].push_back(b-1);
		G[b-1].push_back(a-1);
	}
	for(int i=0;i<N;i++)
	{
		if(G[i].size()>1)
		{
			cout<<dfs(i,-1)<<endl;
			return 0;
		}
	}
}
0