結果

問題 No.1424 Ultrapalindrome
ユーザー jsaibuki1007jsaibuki1007
提出日時 2021-03-12 22:06:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,118 bytes
コンパイル時間 1,982 ms
コンパイル使用メモリ 170,980 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2024-04-22 17:08:24
合計ジャッジ時間 3,319 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,812 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 30 ms
8,260 KB
testcase_10 AC 29 ms
8,404 KB
testcase_11 AC 20 ms
7,668 KB
testcase_12 AC 28 ms
8,124 KB
testcase_13 AC 9 ms
6,944 KB
testcase_14 AC 25 ms
7,832 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 19 ms
7,424 KB
testcase_17 AC 23 ms
7,604 KB
testcase_18 AC 17 ms
7,016 KB
testcase_19 AC 28 ms
7,716 KB
testcase_20 AC 8 ms
6,940 KB
testcase_21 AC 24 ms
7,552 KB
testcase_22 AC 15 ms
6,944 KB
testcase_23 AC 4 ms
6,940 KB
testcase_24 AC 8 ms
6,944 KB
testcase_25 AC 7 ms
6,944 KB
testcase_26 AC 33 ms
7,940 KB
testcase_27 AC 41 ms
9,216 KB
testcase_28 AC 32 ms
8,972 KB
testcase_29 AC 38 ms
15,232 KB
testcase_30 AC 27 ms
9,312 KB
testcase_31 AC 29 ms
9,484 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