結果

問題 No.1424 Ultrapalindrome
ユーザー kotatsugamekotatsugame
提出日時 2021-03-13 04:11:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 77,780 KB
実行使用メモリ 10,656 KB
最終ジャッジ日時 2024-04-22 17:30:27
合計ジャッジ時間 2,955 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,528 KB
testcase_01 AC 4 ms
6,656 KB
testcase_02 AC 4 ms
6,656 KB
testcase_03 AC 3 ms
6,656 KB
testcase_04 AC 3 ms
6,656 KB
testcase_05 AC 3 ms
6,528 KB
testcase_06 AC 4 ms
6,656 KB
testcase_07 AC 3 ms
6,656 KB
testcase_08 AC 3 ms
6,656 KB
testcase_09 AC 56 ms
9,088 KB
testcase_10 AC 58 ms
9,088 KB
testcase_11 AC 39 ms
8,320 KB
testcase_12 AC 52 ms
8,976 KB
testcase_13 AC 16 ms
7,040 KB
testcase_14 AC 46 ms
8,576 KB
testcase_15 AC 3 ms
6,656 KB
testcase_16 AC 37 ms
8,192 KB
testcase_17 AC 43 ms
8,320 KB
testcase_18 AC 29 ms
7,936 KB
testcase_19 AC 47 ms
8,576 KB
testcase_20 AC 13 ms
6,912 KB
testcase_21 AC 38 ms
8,320 KB
testcase_22 AC 25 ms
7,680 KB
testcase_23 AC 7 ms
6,912 KB
testcase_24 AC 13 ms
6,980 KB
testcase_25 AC 11 ms
7,008 KB
testcase_26 AC 57 ms
9,088 KB
testcase_27 AC 78 ms
9,644 KB
testcase_28 AC 69 ms
9,808 KB
testcase_29 AC 72 ms
10,112 KB
testcase_30 AC 56 ms
10,528 KB
testcase_31 AC 66 ms
10,656 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int N;
vector<int>G[1<<17];
int dist[1<<17];
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);
	}
	int id=0;
	while(id<N&&G[id].size()<=2)id++;
	if(id==N)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	for(int i=id+1;i<N;i++)if(G[i].size()>2)
	{
		cout<<"No"<<endl;
		return 0;
	}
	queue<int>P;P.push(id);
	for(int i=0;i<N;i++)dist[i]=1e9;
	dist[id]=0;
	while(!P.empty())
	{
		int u=P.front();P.pop();
		for(int v:G[u])if(dist[v]>dist[u]+1)
		{
			dist[v]=dist[u]+1;
			P.push(v);
		}
	}
	int mx=-1;
	for(int i=0;i<N;i++)if(G[i].size()==1)
	{
		if(mx==-1)mx=dist[i];
		else if(mx!=dist[i])
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}
0