結果

問題 No.1424 Ultrapalindrome
ユーザー chocoruskchocorusk
提出日時 2021-03-12 22:46:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,590 bytes
コンパイル時間 3,742 ms
コンパイル使用メモリ 187,232 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-04-22 17:14:34
合計ジャッジ時間 5,837 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,016 KB
testcase_01 AC 3 ms
5,888 KB
testcase_02 AC 4 ms
6,016 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 4 ms
6,016 KB
testcase_05 AC 3 ms
5,888 KB
testcase_06 AC 3 ms
5,760 KB
testcase_07 AC 3 ms
5,888 KB
testcase_08 AC 3 ms
6,016 KB
testcase_09 AC 58 ms
8,448 KB
testcase_10 AC 59 ms
8,524 KB
testcase_11 AC 43 ms
7,760 KB
testcase_12 AC 60 ms
8,192 KB
testcase_13 AC 17 ms
6,784 KB
testcase_14 AC 48 ms
7,936 KB
testcase_15 AC 4 ms
6,016 KB
testcase_16 AC 36 ms
7,424 KB
testcase_17 AC 43 ms
7,680 KB
testcase_18 AC 30 ms
7,296 KB
testcase_19 AC 49 ms
7,936 KB
testcase_20 AC 13 ms
6,272 KB
testcase_21 AC 38 ms
7,636 KB
testcase_22 AC 24 ms
7,040 KB
testcase_23 AC 7 ms
6,400 KB
testcase_24 AC 12 ms
6,528 KB
testcase_25 AC 11 ms
6,528 KB
testcase_26 AC 62 ms
8,320 KB
testcase_27 AC 82 ms
9,088 KB
testcase_28 AC 69 ms
8,960 KB
testcase_29 AC 73 ms
12,928 KB
testcase_30 AC 58 ms
9,456 KB
testcase_31 AC 67 ms
9,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    if(n<=3){
        cout<<"Yes"<<endl;
        return 0;
    }
    vector<int> g[100010];
    for(int i=0; i<n-1; i++){
        int a, b;
        cin>>a>>b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int r=-1;
    for(int i=0; i<n; i++){
        if(g[i].size()>2){
            r=i;break;
        }
    }
    if(r==-1){
        cout<<"Yes"<<endl;
        return 0;
    }
    for(int i=0; i<n; i++){
        if(i!=r && g[i].size()>2){
            cout<<"No"<<endl;
            return 0;
        }
    }
    int s[100010];
    auto dfs=[&](auto self, int x, int p)->void{
        s[x]=1;
        for(auto y:g[x]){
            if(y==p) continue;
            self(self, y, x);
            s[x]+=s[y];
        }
    };
    dfs(dfs, r, -1);
    for(int i=1; i<g[r].size(); i++){
        if(s[g[r][i]]!=s[g[r][i-1]]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}
0