結果

問題 No.1484 木に数を書き込む問題 / Just Write Numbers! 2
ユーザー kotatsugame
提出日時 2021-04-21 00:00:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 562 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 78,644 KB
実行使用メモリ 11,344 KB
最終ジャッジ日時 2024-07-04 05:31:20
合計ジャッジ時間 4,959 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 12 RE * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-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