結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー rpy3cpprpy3cpp
提出日時 2019-05-06 23:07:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 1,211 bytes
コンパイル時間 1,760 ms
コンパイル使用メモリ 179,080 KB
実行使用メモリ 33,788 KB
最終ジャッジ日時 2023-09-10 22:43:52
合計ジャッジ時間 11,235 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,760 KB
testcase_01 AC 2 ms
8,756 KB
testcase_02 AC 1 ms
8,752 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 83 ms
20,372 KB
testcase_08 AC 39 ms
12,216 KB
testcase_09 AC 47 ms
13,884 KB
testcase_10 AC 35 ms
11,328 KB
testcase_11 AC 150 ms
30,028 KB
testcase_12 AC 151 ms
30,112 KB
testcase_13 AC 151 ms
29,360 KB
testcase_14 AC 144 ms
29,264 KB
testcase_15 AC 161 ms
30,996 KB
testcase_16 AC 152 ms
31,272 KB
testcase_17 AC 159 ms
31,720 KB
testcase_18 AC 95 ms
33,788 KB
testcase_19 AC 95 ms
33,572 KB
testcase_20 AC 105 ms
32,116 KB
testcase_21 AC 104 ms
30,448 KB
20evil_special_uni1.txt TLE -
20evil_special_uni2.txt TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

bool dfs(int a, int b, vector<unordered_map<int, bool>> & dp, const vector<vector<int>> & Es){
    if (dp[a].count(b) > 0) return dp[a][b];
    for (auto c : Es[b]){
        if (c == a) continue;
        if (not dfs(b, c, dp, Es)){
            dp[a][b] = true;
            return true;
        }
    }
    dp[a][b] = false;
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int>> Es(N, vector<int>());
    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);
    }
    vector<unordered_map<int, bool>> dp(N, unordered_map<int, bool>());
    for (int a = 0; a < N; ++a){
        for (auto b : Es[a]){
            dfs(a, b,dp, Es);
        }
    }
    vector<int> ans;
    for (int v = 0; v < N; ++v){
        bool v_wins = true;
        for (auto u : Es[v]){
            if (not dp[v][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