結果

問題 No.1424 Ultrapalindrome
ユーザー milanis48663220milanis48663220
提出日時 2021-03-12 21:37:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,616 bytes
コンパイル時間 1,174 ms
コンパイル使用メモリ 100,860 KB
実行使用メモリ 14,188 KB
最終ジャッジ日時 2024-04-22 17:00:12
合計ジャッジ時間 2,716 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,888 KB
testcase_01 AC 4 ms
5,760 KB
testcase_02 AC 4 ms
5,888 KB
testcase_03 AC 4 ms
5,760 KB
testcase_04 AC 4 ms
6,016 KB
testcase_05 AC 3 ms
5,888 KB
testcase_06 AC 4 ms
5,888 KB
testcase_07 AC 4 ms
5,760 KB
testcase_08 AC 3 ms
5,760 KB
testcase_09 AC 37 ms
8,516 KB
testcase_10 AC 36 ms
8,576 KB
testcase_11 AC 25 ms
7,544 KB
testcase_12 AC 34 ms
8,256 KB
testcase_13 AC 11 ms
6,528 KB
testcase_14 AC 27 ms
7,840 KB
testcase_15 AC 4 ms
6,016 KB
testcase_16 AC 21 ms
7,552 KB
testcase_17 AC 26 ms
7,608 KB
testcase_18 AC 19 ms
7,552 KB
testcase_19 AC 30 ms
7,884 KB
testcase_20 AC 9 ms
6,400 KB
testcase_21 AC 25 ms
7,784 KB
testcase_22 AC 16 ms
6,912 KB
testcase_23 AC 6 ms
6,272 KB
testcase_24 AC 8 ms
6,272 KB
testcase_25 AC 8 ms
6,400 KB
testcase_26 AC 40 ms
8,284 KB
testcase_27 AC 46 ms
9,216 KB
testcase_28 AC 32 ms
8,972 KB
testcase_29 AC 38 ms
14,188 KB
testcase_30 AC 28 ms
10,008 KB
testcase_31 AC 32 ms
10,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

vector<int> g[100000];
int depth[100000];
bool used[100000];

void dfs(int v, int d){
    used[v] = true;
    depth[v] = d;
    for(int to : g[v]){
        if(!used[to]) dfs(to, d+1);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<int> deg(n);
    for(int i = 0; i < n-1; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        deg[a]++;
        deg[b]++;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(deg[i] >= 3) cnt++;
    }
    if(cnt > 1){
        cout << "No" << endl;
        return 0;
    }else if(cnt == 0){
        cout << "Yes" << endl;
        return 0;
    }
    for(int i = 0; i < n; i++){
        if(deg[i] >= 3) dfs(i, 0);
    }
    set<int> st;
    for(int i = 0; i < n; i++){
        if(deg[i] == 1){
            st.insert(depth[i]);
        }
    }
    if(st.size() == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}
0