結果

問題 No.1424 Ultrapalindrome
ユーザー ocvret_ocvret_
提出日時 2021-03-12 22:30:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,050 bytes
コンパイル時間 1,609 ms
コンパイル使用メモリ 167,940 KB
実行使用メモリ 14,592 KB
最終ジャッジ日時 2024-04-22 17:11:49
合計ジャッジ時間 3,694 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,248 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 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 63 ms
8,576 KB
testcase_10 AC 63 ms
8,576 KB
testcase_11 AC 47 ms
7,168 KB
testcase_12 AC 66 ms
8,192 KB
testcase_13 AC 17 ms
5,376 KB
testcase_14 AC 49 ms
7,552 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 40 ms
6,656 KB
testcase_17 AC 49 ms
7,424 KB
testcase_18 AC 31 ms
6,272 KB
testcase_19 AC 51 ms
7,424 KB
testcase_20 AC 14 ms
5,376 KB
testcase_21 AC 40 ms
6,656 KB
testcase_22 AC 25 ms
5,632 KB
testcase_23 AC 6 ms
5,376 KB
testcase_24 AC 11 ms
5,376 KB
testcase_25 AC 11 ms
5,376 KB
testcase_26 AC 66 ms
7,936 KB
testcase_27 AC 85 ms
9,984 KB
testcase_28 AC 73 ms
14,464 KB
testcase_29 AC 74 ms
14,592 KB
testcase_30 AC 57 ms
10,128 KB
testcase_31 AC 70 ms
10,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

vector<int> d(200000,-1);
void dfs(vector<vector<int>> &v,int ov){
  for(auto nv : v[ov]){
    if(d[nv] != -1)continue;
    d[nv] = d[ov] + 1;
    dfs(v,nv);
  }
}

int main(){
  
  int n;
  cin >> n;
  vector<int> deg(n);
  vector<vector<int>> v(n);
  rep(i,n-1){
    int a,b;cin >> a >> b;
    a--;b--;
    deg[a]++;deg[b]++;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int cnt = 0;
  int root = 0;
  rep(i,n)if(deg[i] >= 3)cnt++,root = i;
  d[root] = 0;
  dfs(v,root);
  int mn = MOD,mx = 0;
  rep(i,n)if(i != root && deg[i] == 1)mn = min(mn,d[i]),mx = max(mx,d[i]);
  if(cnt == 0)mn = mx;
  cout << (mn == mx && cnt <= 1 ? "Yes\n" : "No\n");
  


  return 0;
}
0