結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー rpy3cpprpy3cpp
提出日時 2019-05-06 23:21:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 1,163 bytes
コンパイル時間 1,733 ms
コンパイル使用メモリ 178,616 KB
実行使用メモリ 19,300 KB
最終ジャッジ日時 2023-09-10 23:04:05
合計ジャッジ時間 11,597 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
12,480 KB
testcase_01 AC 2 ms
9,876 KB
testcase_02 AC 4 ms
19,300 KB
testcase_03 AC 4 ms
5,312 KB
testcase_04 AC 4 ms
5,252 KB
testcase_05 AC 4 ms
5,284 KB
testcase_06 AC 4 ms
5,192 KB
testcase_07 AC 109 ms
12,672 KB
testcase_08 AC 44 ms
9,176 KB
testcase_09 AC 56 ms
9,744 KB
testcase_10 AC 37 ms
8,924 KB
testcase_11 AC 219 ms
17,996 KB
testcase_12 AC 217 ms
17,980 KB
testcase_13 AC 216 ms
17,716 KB
testcase_14 AC 215 ms
17,940 KB
testcase_15 AC 229 ms
18,040 KB
testcase_16 AC 219 ms
17,852 KB
testcase_17 AC 218 ms
17,968 KB
testcase_18 AC 120 ms
18,744 KB
testcase_19 AC 140 ms
18,780 KB
testcase_20 AC 150 ms
18,444 KB
testcase_21 AC 142 ms
18,136 KB
20evil_special_uni1.txt TLE -
20evil_special_uni2.txt TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr long long shift = 1LL<<32;

unordered_map<long long, bool> dp;
vector<vector<int>> Es(100000, vector<int>());

bool dfs(int a, int b){
    long long ab = a * shift + b;
    if (dp.count(ab) > 0) return dp[ab];
    for (auto c : Es[b]){
        if (c == a) continue;
        if (not dfs(b, c)){
            dp[ab] = true;
            return true;
        }
    }
    dp[ab] = false;
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    for (int i = 1; i < N; ++i){
        int a, b;
        cin >> a >> b;
        Es[a-1].push_back(b-1);
        Es[b-1].push_back(a-1);
    }
    for (int a = 0; a < N; ++a){
        for (auto b : Es[a]){
            dfs(a, b);
        }
    }
    vector<int> ans;
    for (int v = 0; v < N; ++v){
        bool v_wins = true;
        for (auto u : Es[v]){
            if (not dp[v * shift + u]){
                v_wins = false;
                break;
            }
        }
        if (v_wins) ans.push_back(v + 1);
    }
    cout << ans.size() << '\n';
    for (auto v : ans) cout << v << '\n'; 
    return 0;
}

0