結果

問題 No.1424 Ultrapalindrome
ユーザー 👑 NachiaNachia
提出日時 2021-03-12 22:55:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 4,407 ms
コンパイル使用メモリ 257,544 KB
実行使用メモリ 9,976 KB
最終ジャッジ日時 2024-04-22 17:14:52
合計ジャッジ時間 5,943 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 31 ms
7,680 KB
testcase_10 AC 32 ms
7,680 KB
testcase_11 AC 22 ms
6,400 KB
testcase_12 AC 28 ms
7,296 KB
testcase_13 AC 9 ms
5,376 KB
testcase_14 AC 22 ms
6,656 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 19 ms
6,016 KB
testcase_17 AC 22 ms
6,528 KB
testcase_18 AC 16 ms
5,632 KB
testcase_19 AC 24 ms
6,940 KB
testcase_20 AC 6 ms
5,376 KB
testcase_21 AC 20 ms
6,400 KB
testcase_22 AC 13 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 7 ms
5,376 KB
testcase_25 AC 6 ms
5,376 KB
testcase_26 AC 32 ms
7,424 KB
testcase_27 AC 38 ms
8,960 KB
testcase_28 AC 31 ms
8,832 KB
testcase_29 AC 32 ms
9,216 KB
testcase_30 AC 27 ms
9,976 KB
testcase_31 AC 30 ms
9,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
using mll=atcoder::static_modint<1000000007>;

int N;
vector<vector<int>> E;
vector<int> D;

int main(){
  scanf("%d",&N);
  E.resize(N);
  rep(i,N-1){
    int u,v; scanf("%d%d",&u,&v); u--; v--;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  int splitCount=0;
  rep(i,N) if(E[i].size()>2) splitCount++;
  if(splitCount==0){ printf("Yes\n"); return 0; }
  if(splitCount>=2){ printf("No\n"); return 0; }

  queue<int> Q;
  D.assign(N,-1);
  rep(i,N) if(E[i].size()>2){ D[i]=0; Q.push(i); }
  while(Q.size()){
    int p=Q.front(); Q.pop();
    for(int e:E[p]) if(D[e]==-1){ D[e]=D[p]+1; Q.push(e); }
  }
  int x=-1;
  rep(i,N) if(E[i].size()==1){
    if(x==-1) x=D[i];
    else if(x!=D[i]){ printf("No\n"); return 0; }
  }
  
  printf("Yes\n");
  return 0;
}
0