結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー lumc_lumc_
提出日時 2018-12-15 14:36:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 1,332 bytes
コンパイル時間 978 ms
コンパイル使用メモリ 114,036 KB
実行使用メモリ 28,284 KB
最終ジャッジ日時 2023-10-25 22:22:06
合計ジャッジ時間 3,751 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,092 KB
testcase_01 AC 4 ms
10,092 KB
testcase_02 AC 4 ms
10,092 KB
testcase_03 AC 5 ms
10,412 KB
testcase_04 AC 5 ms
10,412 KB
testcase_05 AC 4 ms
10,412 KB
testcase_06 AC 5 ms
10,412 KB
testcase_07 AC 63 ms
20,940 KB
testcase_08 AC 31 ms
15,692 KB
testcase_09 AC 38 ms
16,748 KB
testcase_10 AC 29 ms
15,164 KB
testcase_11 AC 103 ms
26,780 KB
testcase_12 AC 103 ms
26,860 KB
testcase_13 AC 99 ms
26,516 KB
testcase_14 AC 99 ms
26,444 KB
testcase_15 AC 109 ms
27,384 KB
testcase_16 AC 108 ms
27,456 KB
testcase_17 AC 112 ms
27,756 KB
testcase_18 AC 117 ms
28,284 KB
testcase_19 AC 101 ms
28,168 KB
testcase_20 AC 121 ms
27,420 KB
testcase_21 AC 112 ms
26,676 KB
20evil_special_uni1.txt AC 134 ms
27,652 KB
20evil_special_uni2.txt AC 125 ms
26,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

const int N = 1e5;
vector< vector< int > > g(N);
using Value = int;
map< int, Value > dp[N]; // dp[i][j] := jを親としたときの, 部分木iがwinning何本と繋がっているか

Value dfs(int i, int p, int f) {
  if(dp[i].count(p)) return dp[i][p];
  int deg = g[i].size() - (p != -1);
  Value res = 0;
  if(f || p == -1) {
    // O(deg)
    // go only child
    for(int j : g[i])
      if(j != p) {
        res += !dfs(j, i, f);
      }
  } else {
    // O(1)
    res = dfs(i, -1, f) - (!dfs(p, i, f));
  }
  return dp[i][p] = res;
}

int n;
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n;
  for(int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  dfs(0, -1, 1);
  vector<int> v;
  for(int i = 0; i < n; i++) if(!dfs(i, -1, 0)) v.emplace_back(i);
  cout << v.size() << "\n";
  for(int e : v) cout << e + 1 << "\n";
  return 0;
}
0