結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-01-02 22:57:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 2,629 bytes
コンパイル時間 1,604 ms
コンパイル使用メモリ 167,224 KB
実行使用メモリ 10,472 KB
最終ジャッジ日時 2023-08-14 04:29:25
合計ジャッジ時間 5,180 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,908 KB
testcase_01 AC 3 ms
5,944 KB
testcase_02 AC 3 ms
5,852 KB
testcase_03 AC 4 ms
6,040 KB
testcase_04 AC 4 ms
6,016 KB
testcase_05 AC 3 ms
6,172 KB
testcase_06 AC 3 ms
5,964 KB
testcase_07 AC 36 ms
8,476 KB
testcase_08 AC 20 ms
7,352 KB
testcase_09 AC 23 ms
7,616 KB
testcase_10 AC 18 ms
7,144 KB
testcase_11 AC 71 ms
9,784 KB
testcase_12 AC 68 ms
9,836 KB
testcase_13 AC 64 ms
9,700 KB
testcase_14 AC 61 ms
9,896 KB
testcase_15 AC 68 ms
9,956 KB
testcase_16 AC 66 ms
10,104 KB
testcase_17 AC 66 ms
10,040 KB
testcase_18 AC 51 ms
10,416 KB
testcase_19 AC 49 ms
10,472 KB
testcase_20 AC 51 ms
10,348 KB
testcase_21 AC 47 ms
10,028 KB
20evil_special_uni1.txt AC 60 ms
10,228 KB
20evil_special_uni2.txt AC 59 ms
9,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/





int N;
vector<int> E[101010];
//---------------------------------------------------------------------------------------------------
#define win 1
#define lose 0
int dp[101010];
int dfs1(int cu, int pa = -1) {
    dp[cu] = win;
    fore(to, E[cu]) if (to != pa) if (dfs1(to, cu) == win) dp[cu] = lose;
    return dp[cu];
}
int ans[101010];
void dfs2(int cu, int pa = -1) {
    ans[cu] = win;
    fore(to, E[cu]) if (dp[to] == win) ans[cu] = lose;

    vector<int> wins;
    fore(to, E[cu]) if (dp[to] == win) wins.push_back(to);

    if (wins.size() == 0) {
        dp[cu] = win;
        fore(to, E[cu]) if (to != pa) dfs2(to, cu);
        return;
    } else if(1 < wins.size()) {
        dp[cu] = lose;
        fore(to, E[cu]) if (to != pa) dfs2(to, cu);
        return;
    } else {
        fore(to, E[cu]) if (to != pa) {
            if(wins[0] == to) dp[cu] = win;
            else dp[cu] = lose;
            dfs2(to, cu);
        }
        return;
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N - 1) {
        int a, b; cin >> a >> b;
        a--; b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    dfs1(0);
    dfs2(0);

    vector<int> v;
    rep(i, 0, N) if (ans[i]) v.push_back(i);
    int n = v.size();
    printf("%d\n", n);
    fore(i, v) printf("%d\n", i + 1);
}
0