結果

問題 No.1424 Ultrapalindrome
ユーザー cureskolcureskol
提出日時 2022-05-29 13:32:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 2,280 ms
コンパイル使用メモリ 213,876 KB
実行使用メモリ 9,916 KB
最終ジャッジ日時 2023-10-20 23:46:38
合計ジャッジ時間 4,118 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 35 ms
7,944 KB
testcase_10 AC 35 ms
7,968 KB
testcase_11 AC 25 ms
6,700 KB
testcase_12 AC 32 ms
7,704 KB
testcase_13 AC 9 ms
4,784 KB
testcase_14 AC 26 ms
6,984 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 21 ms
6,284 KB
testcase_17 AC 25 ms
6,812 KB
testcase_18 AC 17 ms
5,832 KB
testcase_19 AC 31 ms
6,832 KB
testcase_20 AC 6 ms
4,444 KB
testcase_21 AC 24 ms
6,196 KB
testcase_22 AC 14 ms
5,276 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 6 ms
4,364 KB
testcase_25 AC 6 ms
4,348 KB
testcase_26 AC 41 ms
7,444 KB
testcase_27 AC 43 ms
9,396 KB
testcase_28 AC 30 ms
9,108 KB
testcase_29 AC 30 ms
9,108 KB
testcase_30 AC 25 ms
9,916 KB
testcase_31 AC 29 ms
9,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

using ll =long long;

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;cin>>n;
  vector<vector<int>> g(n);
  REP(_,n-1){
    int u,v;cin>>u>>v;u--;v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int id=-1;
  queue<int> que;
  REP(i,n)
    if(g[i].size()>2){
      if(~id)fin("No");
      id=i;
    }
    else if(g[i].size()==1)
      que.push(i);

  if(id<0)fin("Yes");

  set<int> se;

  while(que.size()){
    int p=que.front();que.pop();
    int cnt=0;
    int pre=-1;
    while(p!=id){
      int tmp=p;
      if(g[p][0]==pre)p=g[p][1];
      else p=g[p][0];
      pre=tmp;
      cnt++;
    }
    se.insert(cnt);
  }
  if(se.size()==1)fin("Yes");
  fin("No");
}
  
0