結果

問題 No.1424 Ultrapalindrome
ユーザー 👑 箱星箱星
提出日時 2020-12-28 05:26:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,453 bytes
コンパイル時間 1,326 ms
コンパイル使用メモリ 95,404 KB
実行使用メモリ 9,104 KB
最終ジャッジ日時 2024-05-03 09:04:34
合計ジャッジ時間 2,802 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 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 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 35 ms
7,808 KB
testcase_10 AC 35 ms
7,808 KB
testcase_11 AC 22 ms
6,528 KB
testcase_12 AC 37 ms
7,552 KB
testcase_13 AC 9 ms
5,376 KB
testcase_14 AC 26 ms
6,528 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 20 ms
6,016 KB
testcase_17 AC 25 ms
6,528 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 45 ms
8,836 KB
testcase_28 AC 31 ms
8,704 KB
testcase_29 AC 32 ms
8,704 KB
testcase_30 WA -
testcase_31 AC 29 ms
8,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
using ll = long long;
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<int>> adj(n, vector<int>());
    for (int i = 0; i < n - 1; i++)
    {
        int v1, v2;
        cin >> v1 >> v2;
        v1--;
        v2--;
        adj[v1].push_back(v2);
        adj[v2].push_back(v1);
    }
    vector<int> lst;
    for (int i = 0; i < n; i++)
    {
        if (adj[i].size() >= 3)
        {
            lst.push_back(i);
        }
    }
    if (lst.size() >= 2)
    {
        cout << "No" << endl;
    }
    else if (lst.size() == 0)
    {
        cout << "Yes" << endl;
    }
    else {
        set<int> lens;
        queue<pair<int, pair<int, int>>> que;
        while (!que.empty())
        {
            auto data = que.front();
            que.pop();
            int v = data.first;
            int p = data.second.first;
            int d = data.second.second;
            bool isleaf = true;
            for (int w : adj[v])
            {
                if (w != p)
                {
                    isleaf = false;
                    que.push(make_pair(w, make_pair(v, d + 1)));
                }
            }
            if (isleaf)
            {
                lens.insert(d);
            }
        }
        cout << (lens.size() == 1 ? "Yes" : "No") << endl;
    }
}
0