結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー lumc_lumc_
提出日時 2018-03-12 01:13:33
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 614 bytes
コンパイル時間 1,668 ms
コンパイル使用メモリ 169,828 KB
実行使用メモリ 34,812 KB
最終ジャッジ日時 2023-10-25 21:47:28
合計ジャッジ時間 9,840 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
15,640 KB
testcase_01 AC 5 ms
11,292 KB
testcase_02 AC 5 ms
11,292 KB
testcase_03 AC 6 ms
11,460 KB
testcase_04 AC 7 ms
11,512 KB
testcase_05 AC 7 ms
11,480 KB
testcase_06 AC 6 ms
11,420 KB
testcase_07 AC 181 ms
25,516 KB
testcase_08 AC 84 ms
18,740 KB
testcase_09 AC 102 ms
20,148 KB
testcase_10 AC 74 ms
18,056 KB
testcase_11 AC 306 ms
33,396 KB
testcase_12 AC 312 ms
33,600 KB
testcase_13 AC 315 ms
32,932 KB
testcase_14 AC 299 ms
32,868 KB
testcase_15 AC 324 ms
34,292 KB
testcase_16 AC 324 ms
34,348 KB
testcase_17 AC 322 ms
34,812 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;
}

int main() {
  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);
  }
  
  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