結果

問題 No.1484 木に数を書き込む問題 / Just Write Numbers! 2
ユーザー kotatsugamekotatsugame
提出日時 2021-04-21 00:01:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 565 bytes
コンパイル時間 780 ms
コンパイル使用メモリ 78,208 KB
実行使用メモリ 17,964 KB
最終ジャッジ日時 2023-09-17 09:00:55
合計ジャッジ時間 5,952 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,444 KB
testcase_01 AC 4 ms
9,472 KB
testcase_02 AC 4 ms
9,424 KB
testcase_03 AC 4 ms
9,428 KB
testcase_04 AC 7 ms
9,556 KB
testcase_05 AC 16 ms
10,156 KB
testcase_06 AC 17 ms
10,152 KB
testcase_07 AC 11 ms
9,812 KB
testcase_08 AC 19 ms
10,128 KB
testcase_09 AC 16 ms
10,168 KB
testcase_10 AC 17 ms
10,020 KB
testcase_11 AC 14 ms
9,940 KB
testcase_12 AC 13 ms
9,864 KB
testcase_13 AC 6 ms
9,476 KB
testcase_14 AC 165 ms
15,216 KB
testcase_15 AC 157 ms
14,984 KB
testcase_16 AC 140 ms
14,556 KB
testcase_17 AC 93 ms
13,460 KB
testcase_18 AC 183 ms
15,780 KB
testcase_19 AC 232 ms
16,932 KB
testcase_20 AC 227 ms
16,936 KB
testcase_21 AC 226 ms
16,764 KB
testcase_22 AC 227 ms
16,776 KB
testcase_23 AC 231 ms
16,948 KB
testcase_24 AC 231 ms
16,736 KB
testcase_25 AC 236 ms
16,776 KB
testcase_26 AC 236 ms
16,792 KB
testcase_27 AC 233 ms
16,892 KB
testcase_28 AC 240 ms
16,880 KB
testcase_29 AC 139 ms
16,508 KB
testcase_30 AC 141 ms
16,452 KB
testcase_31 AC 110 ms
17,964 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:26:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   26 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int N;
vector<int>G[2<<17];
pair<int,int>f(int s)
{
	vector<int>d(N,1e9);
	d[s]=0;
	queue<int>P;
	P.push(s);
	pair<int,int>ret;
	while(!P.empty())
	{
		int u=P.front();P.pop();
		ret=make_pair(u,d[u]);
		for(int v:G[u])if(d[v]>d[u]+1)
		{
			d[v]=d[u]+1;
			P.push(v);
		}
	}
	return ret;
}
main()
{
	cin>>N;
	for(int i=1;i<N;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	pair<int,int>p=f(0);
	pair<int,int>q=f(p.first);
	cout<<2*N-q.second-2<<endl;
}
0