結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー lumc_lumc_
提出日時 2018-03-12 01:24:01
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 937 bytes
コンパイル時間 2,484 ms
コンパイル使用メモリ 170,880 KB
実行使用メモリ 34,892 KB
最終ジャッジ日時 2023-10-25 21:47:55
合計ジャッジ時間 8,690 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,272 KB
testcase_01 AC 6 ms
11,272 KB
testcase_02 AC 6 ms
11,272 KB
testcase_03 AC 7 ms
11,440 KB
testcase_04 AC 7 ms
11,492 KB
testcase_05 AC 7 ms
11,460 KB
testcase_06 AC 7 ms
11,400 KB
testcase_07 AC 204 ms
25,556 KB
testcase_08 AC 96 ms
18,752 KB
testcase_09 AC 113 ms
20,164 KB
testcase_10 AC 82 ms
18,064 KB
testcase_11 AC 349 ms
33,464 KB
testcase_12 AC 343 ms
33,672 KB
testcase_13 AC 336 ms
33,000 KB
testcase_14 AC 339 ms
32,936 KB
testcase_15 AC 356 ms
34,368 KB
testcase_16 AC 364 ms
34,424 KB
testcase_17 AC 378 ms
34,892 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
20evil_special_uni1.txt -- -
20evil_special_uni2.txt -- -
権限があれば一括ダウンロードができます

ソースコード

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) flag |= dfs(u, v);
  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