結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-01-02 22:57:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 2,629 bytes
コンパイル時間 1,751 ms
コンパイル使用メモリ 170,436 KB
実行使用メモリ 10,996 KB
最終ジャッジ日時 2024-05-01 17:17:28
合計ジャッジ時間 4,890 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,812 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 40 ms
8,772 KB
testcase_08 AC 21 ms
7,424 KB
testcase_09 AC 24 ms
7,784 KB
testcase_10 AC 18 ms
7,320 KB
testcase_11 AC 62 ms
9,980 KB
testcase_12 AC 70 ms
10,020 KB
testcase_13 AC 67 ms
9,900 KB
testcase_14 AC 61 ms
9,876 KB
testcase_15 AC 68 ms
10,236 KB
testcase_16 AC 76 ms
10,128 KB
testcase_17 AC 74 ms
10,220 KB
testcase_18 AC 55 ms
10,996 KB
testcase_19 AC 55 ms
10,740 KB
testcase_20 AC 55 ms
10,484 KB
testcase_21 AC 52 ms
10,240 KB
20evil_special_uni1.txt AC 64 ms
10,288 KB
20evil_special_uni2.txt AC 60 ms
10,048 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