結果

問題 No.1424 Ultrapalindrome
ユーザー jsaibuki1007jsaibuki1007
提出日時 2021-03-12 22:06:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,118 bytes
コンパイル時間 1,686 ms
コンパイル使用メモリ 172,380 KB
実行使用メモリ 15,248 KB
最終ジャッジ日時 2023-08-04 19:03:45
合計ジャッジ時間 3,290 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,812 KB
testcase_01 AC 3 ms
5,712 KB
testcase_02 AC 3 ms
5,712 KB
testcase_03 AC 3 ms
5,720 KB
testcase_04 AC 3 ms
5,712 KB
testcase_05 AC 3 ms
5,708 KB
testcase_06 AC 3 ms
5,696 KB
testcase_07 AC 3 ms
5,696 KB
testcase_08 AC 3 ms
5,780 KB
testcase_09 AC 27 ms
8,264 KB
testcase_10 AC 28 ms
8,324 KB
testcase_11 AC 20 ms
7,612 KB
testcase_12 AC 26 ms
8,100 KB
testcase_13 AC 9 ms
6,444 KB
testcase_14 AC 21 ms
7,712 KB
testcase_15 AC 3 ms
5,720 KB
testcase_16 AC 17 ms
7,244 KB
testcase_17 AC 20 ms
7,660 KB
testcase_18 AC 15 ms
6,960 KB
testcase_19 AC 23 ms
7,540 KB
testcase_20 AC 7 ms
6,228 KB
testcase_21 AC 18 ms
7,296 KB
testcase_22 AC 13 ms
6,752 KB
testcase_23 AC 5 ms
5,992 KB
testcase_24 AC 7 ms
6,264 KB
testcase_25 AC 7 ms
6,284 KB
testcase_26 AC 28 ms
7,892 KB
testcase_27 AC 33 ms
9,040 KB
testcase_28 AC 29 ms
8,888 KB
testcase_29 AC 34 ms
15,248 KB
testcase_30 AC 25 ms
9,416 KB
testcase_31 AC 27 ms
9,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;
set<int> st;
vector<int> nodes[100100];

void dfs(int p, int s, int depth){
    bool is_leaf = true;
    for(auto to: nodes[s]){
        if(to == p) continue;
        is_leaf = false;
        dfs(s, to, depth+1);
    }
    if(is_leaf) st.insert(depth);
    return;
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    rep(i, N-1){
        int a, b; cin >> a >> b;
        a--; b--;
        nodes[a].push_back(b);
        nodes[b].push_back(a);
    }
    vector<int> jisuu_cnt(N, 0);
    int root = -1;
    rep(i, N){
        jisuu_cnt[nodes[i].size()]++;
        if(nodes[i].size() >= 3) root = i;
    }
    if(jisuu_cnt[1]+jisuu_cnt[2] < N-1) cout << "No" << endl;
    else if(jisuu_cnt[1]+jisuu_cnt[2] == N) cout << "Yes" << endl;
    else{
        dfs(-1, root, 0);
        if(st.size() == 1) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    
    return 0;
}
0