結果

問題 No.1484 木に数を書き込む問題 / Just Write Numbers! 2
ユーザー kotatsugamekotatsugame
提出日時 2021-04-21 00:00:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 562 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 77,256 KB
実行使用メモリ 11,208 KB
最終ジャッジ日時 2023-09-17 09:00:06
合計ジャッジ時間 5,528 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 WA -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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[1<<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<<endl;
}
0