結果

問題 No.1424 Ultrapalindrome
ユーザー cureskolcureskol
提出日時 2022-05-29 13:31:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 820 bytes
コンパイル時間 4,074 ms
コンパイル使用メモリ 213,952 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2023-10-20 23:46:33
合計ジャッジ時間 8,146 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

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){
      if(g[p][0]==pre)p=g[p][1];
      else p=g[p][0];
      cnt++;
    }
    se.insert(cnt);
  }
  if(se.size()==1)fin("Yes");
  fin("No");
}
  
0