結果

問題 No.1928 Make a Binary Tree
ユーザー kotatsugamekotatsugame
提出日時 2022-05-07 02:20:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 251 ms / 3,000 ms
コード長 651 bytes
コンパイル時間 679 ms
コンパイル使用メモリ 76,824 KB
実行使用メモリ 43,844 KB
最終ジャッジ日時 2023-09-20 10:40:03
合計ジャッジ時間 9,597 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,508 KB
testcase_01 AC 5 ms
9,488 KB
testcase_02 AC 4 ms
9,488 KB
testcase_03 AC 4 ms
9,492 KB
testcase_04 AC 4 ms
9,476 KB
testcase_05 AC 4 ms
9,600 KB
testcase_06 AC 4 ms
9,528 KB
testcase_07 AC 4 ms
9,536 KB
testcase_08 AC 5 ms
9,560 KB
testcase_09 AC 4 ms
9,476 KB
testcase_10 AC 4 ms
9,684 KB
testcase_11 AC 4 ms
9,608 KB
testcase_12 AC 4 ms
9,496 KB
testcase_13 AC 4 ms
9,500 KB
testcase_14 AC 4 ms
9,496 KB
testcase_15 AC 11 ms
10,212 KB
testcase_16 AC 10 ms
9,876 KB
testcase_17 AC 9 ms
9,728 KB
testcase_18 AC 11 ms
10,080 KB
testcase_19 AC 5 ms
9,540 KB
testcase_20 AC 9 ms
9,792 KB
testcase_21 AC 6 ms
9,688 KB
testcase_22 AC 10 ms
9,920 KB
testcase_23 AC 8 ms
9,812 KB
testcase_24 AC 12 ms
10,064 KB
testcase_25 AC 12 ms
9,924 KB
testcase_26 AC 202 ms
17,532 KB
testcase_27 AC 119 ms
14,576 KB
testcase_28 AC 134 ms
14,736 KB
testcase_29 AC 242 ms
18,592 KB
testcase_30 AC 109 ms
14,020 KB
testcase_31 AC 150 ms
15,660 KB
testcase_32 AC 225 ms
18,204 KB
testcase_33 AC 125 ms
14,624 KB
testcase_34 AC 154 ms
15,968 KB
testcase_35 AC 147 ms
16,008 KB
testcase_36 AC 182 ms
34,540 KB
testcase_37 AC 187 ms
19,832 KB
testcase_38 AC 4 ms
9,476 KB
testcase_39 AC 195 ms
31,236 KB
testcase_40 AC 196 ms
31,344 KB
testcase_41 AC 194 ms
31,172 KB
testcase_42 AC 197 ms
31,300 KB
testcase_43 AC 189 ms
31,388 KB
testcase_44 AC 190 ms
31,140 KB
testcase_45 AC 191 ms
31,156 KB
testcase_46 AC 192 ms
31,196 KB
testcase_47 AC 200 ms
31,516 KB
testcase_48 AC 194 ms
31,176 KB
testcase_49 AC 167 ms
43,844 KB
testcase_50 AC 205 ms
15,776 KB
testcase_51 AC 208 ms
15,776 KB
testcase_52 AC 201 ms
15,724 KB
testcase_53 AC 211 ms
15,804 KB
testcase_54 AC 207 ms
16,076 KB
testcase_55 AC 157 ms
34,600 KB
testcase_56 AC 250 ms
19,192 KB
testcase_57 AC 251 ms
18,940 KB
testcase_58 AC 245 ms
19,032 KB
testcase_59 AC 184 ms
25,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:36:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   36 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<set>
#include<vector>
using namespace std;
int N;
vector<int>G[2<<17];
multiset<int>ret;
int dfs(int u,int p)
{
	int ch=1;
	multiset<int>now;
	for(int v:G[u])if(v!=p)
	{
		int c=dfs(v,u);
		if(now.size()<ret.size())now.swap(ret);
		for(int d:ret)now.insert(d);
		now.insert(c);
	}
	if(!now.empty())
	{
		auto it=now.end();
		it--;
		ch+=*it;
		now.erase(it);
		if(!now.empty())
		{
			auto it=now.end();
			it--;
			ch+=*it;
			now.erase(it);
		}
	}
	ret.swap(now);
	return ch;
}
main()
{
	cin>>N;
	for(int i=1;i<N;i++)
	{
		int u,v;cin>>u>>v;u--,v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	cout<<dfs(0,-1)<<endl;
}
0