結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー koba-e964koba-e964
提出日時 2018-12-16 12:03:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 1,629 bytes
コンパイル時間 2,888 ms
コンパイル使用メモリ 113,628 KB
実行使用メモリ 19,544 KB
最終ジャッジ日時 2023-10-25 22:09:08
合計ジャッジ時間 3,226 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,608 KB
testcase_01 AC 3 ms
10,608 KB
testcase_02 AC 3 ms
10,604 KB
testcase_03 AC 3 ms
10,664 KB
testcase_04 AC 5 ms
10,676 KB
testcase_05 AC 5 ms
10,668 KB
testcase_06 AC 4 ms
10,648 KB
testcase_07 AC 37 ms
14,540 KB
testcase_08 AC 21 ms
12,704 KB
testcase_09 AC 23 ms
13,100 KB
testcase_10 AC 18 ms
12,528 KB
testcase_11 AC 56 ms
16,640 KB
testcase_12 AC 58 ms
16,680 KB
testcase_13 AC 54 ms
16,512 KB
testcase_14 AC 54 ms
16,488 KB
testcase_15 AC 62 ms
16,856 KB
testcase_16 AC 60 ms
16,888 KB
testcase_17 AC 62 ms
17,012 KB
testcase_18 AC 76 ms
19,524 KB
testcase_19 AC 67 ms
19,544 KB
testcase_20 AC 60 ms
19,208 KB
testcase_21 AC 58 ms
18,716 KB
20evil_special_uni1.txt AC 66 ms
17,104 KB
20evil_special_uni2.txt AC 57 ms
16,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

const int N = 100100;
VI g[N];
set<int> dp[N]; // children that players are able to win on
int dp_par[N];

int dfs1(int v, int par) {
  int can_win = 1;
  for (int w: g[v]) {
    if (par == w) continue;
    int res = dfs1(w, v);
    if (res == 1) {
      dp[v].insert(w);
    }
    can_win &= 1 - res;
  }
  return can_win;
}

void dfs2(int v, int par, int par_result) {
  for (int w: g[v]) {
    if (par == w) continue;
    bool incl = 0;
    if (dp[v].size() == 0 || (dp[v].size() == 1 && dp[v].count(w))) {
      incl = 1;
    }
    dfs2(w, v, incl && !par_result);
  }
  dp_par[v] = par_result;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  REP(i, 0, n - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs1(0, -1);
  dfs2(0, -1, 0);
  VI can_win;
  REP(i, 0, n) {
    if (dp[i].size() == 0 && dp_par[i] == 0) {
      can_win.push_back(i);
    }
  }
  cout << can_win.size() << "\n";
  for (int v: can_win) cout << v + 1 << "\n";
}
0