結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー koba-e964koba-e964
提出日時 2018-12-16 11:56:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 1,791 bytes
コンパイル時間 851 ms
コンパイル使用メモリ 102,892 KB
実行使用メモリ 19,396 KB
最終ジャッジ日時 2023-10-25 22:08:24
合計ジャッジ時間 4,101 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
10,512 KB
testcase_01 AC 4 ms
10,512 KB
testcase_02 AC 4 ms
10,508 KB
testcase_03 AC 4 ms
10,564 KB
testcase_04 AC 4 ms
10,576 KB
testcase_05 AC 4 ms
10,568 KB
testcase_06 AC 3 ms
10,548 KB
testcase_07 AC 62 ms
14,440 KB
testcase_08 AC 34 ms
12,604 KB
testcase_09 AC 39 ms
13,000 KB
testcase_10 AC 30 ms
12,424 KB
testcase_11 AC 106 ms
16,540 KB
testcase_12 AC 102 ms
16,580 KB
testcase_13 AC 97 ms
16,408 KB
testcase_14 AC 95 ms
16,388 KB
testcase_15 AC 102 ms
16,756 KB
testcase_16 AC 101 ms
16,788 KB
testcase_17 AC 105 ms
16,912 KB
testcase_18 AC 197 ms
19,376 KB
testcase_19 AC 198 ms
19,396 KB
testcase_20 AC 189 ms
19,060 KB
testcase_21 AC 184 ms
18,568 KB
20evil_special_uni1.txt AC 129 ms
17,004 KB
20evil_special_uni2.txt AC 126 ms
16,664 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);
    }
  }
  if (0) {
    REP(i, 0, n) {
      cerr << "dp[" << i << "]:";
      for (int w: dp[i]) cerr << " " << w;
      cerr << endl;
      DEBUGP(dp_par[i]);
    }
  }
  cout << can_win.size() << endl;
  for (int v: can_win) cout << v + 1 << endl;
}
0