結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー lumc_lumc_
提出日時 2018-12-16 01:48:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 976 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 178,860 KB
実行使用メモリ 40,288 KB
最終ジャッジ日時 2023-10-25 22:22:31
合計ジャッジ時間 12,106 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
15,856 KB
testcase_01 AC 4 ms
40,288 KB
testcase_02 AC 4 ms
15,856 KB
testcase_03 AC 6 ms
11,648 KB
testcase_04 AC 6 ms
11,700 KB
testcase_05 AC 5 ms
11,672 KB
testcase_06 AC 5 ms
11,612 KB
testcase_07 AC 135 ms
25,532 KB
testcase_08 AC 67 ms
18,840 KB
testcase_09 AC 80 ms
20,228 KB
testcase_10 AC 61 ms
18,164 KB
testcase_11 AC 223 ms
33,300 KB
testcase_12 AC 231 ms
33,508 KB
testcase_13 AC 227 ms
32,848 KB
testcase_14 AC 222 ms
32,792 KB
testcase_15 AC 239 ms
34,196 KB
testcase_16 AC 242 ms
34,244 KB
testcase_17 AC 256 ms
34,708 KB
testcase_18 AC 249 ms
33,604 KB
testcase_19 AC 263 ms
33,696 KB
testcase_20 AC 271 ms
32,692 KB
testcase_21 AC 252 ms
31,372 KB
20evil_special_uni1.txt TLE -
20evil_special_uni2.txt TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

vector<int> g[100000];
int N; 
unordered_map<int, bool> dp[100000];

bool dfs(int v, int p) {
  if(dp[v].count(p)) return dp[v][p];
  bool flag = 0;
  for(int u : g[v]) if(u != p) if(flag |= dfs(u, v)) break; // 枝刈りで通るマジ?
  return dp[v][p] = !flag;
}

bool isTree() {
  bool flag[N] = {};
  function<void(int, int)> check = [&](int v, int p) {
    flag[v] = 1;
    for(int u : g[v]) if(u != p) check(u, v);
  };
  check(0, -1);
  bool all = 1;
  for(int i = 0; i < N; i++) all &= flag[i];
  return all;
}

int main() {
  cin >> N;
  for(int i = 0; i < N - 1; i++) {
    int a, b; cin >> a >> b; a--; b--;
    assert(0 <= a && a < N && 0 <= b && b < N);
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }

  assert(isTree());
  
  vector<int> ans; ans.reserve(N);
  for(int i = 0; i < N; i++)
    if(dfs(i, -1)) ans.emplace_back(i);

  cout << ans.size() << endl;
  for(int el : ans) cout << el + 1 << endl;
}
0