結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー ei1333333ei1333333
提出日時 2018-12-16 18:33:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 650 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 211,112 KB
実行使用メモリ 27,260 KB
最終ジャッジ日時 2023-10-25 22:18:22
合計ジャッジ時間 11,680 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,740 KB
testcase_01 AC 4 ms
10,636 KB
testcase_02 AC 3 ms
10,632 KB
testcase_03 AC 4 ms
10,752 KB
testcase_04 AC 5 ms
10,792 KB
testcase_05 AC 4 ms
10,768 KB
testcase_06 AC 4 ms
10,728 KB
testcase_07 AC 129 ms
20,688 KB
testcase_08 AC 58 ms
15,912 KB
testcase_09 AC 70 ms
16,944 KB
testcase_10 AC 52 ms
15,424 KB
testcase_11 AC 188 ms
26,248 KB
testcase_12 AC 188 ms
26,408 KB
testcase_13 AC 180 ms
25,932 KB
testcase_14 AC 181 ms
25,896 KB
testcase_15 AC 197 ms
26,912 KB
testcase_16 AC 198 ms
26,928 KB
testcase_17 AC 221 ms
27,260 KB
testcase_18 AC 246 ms
23,560 KB
testcase_19 AC 228 ms
23,516 KB
testcase_20 AC 244 ms
23,060 KB
testcase_21 AC 230 ms
22,464 KB
20evil_special_uni1.txt TLE -
20evil_special_uni2.txt TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

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

bool dfs(int idx, int par) {
  if(dp[idx].count(par)) return dp[idx][par];
  for(auto &to : g[idx]) {
    if(to == par) continue;
    if(!dfs(to, idx)) return dp[idx][par] = true;
  }
  return dp[idx][par] = false;
}

int main() {
  cin >> N;
  for(int i = 1; i < N; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vector< int > ans;
  for(int i = 0; i < N; i++) {
    if(!dfs(i, -1)) ans.push_back(i);
  }
  cout << ans.size() << endl;
  for(auto &p : ans) cout << p + 1 << endl;
}
0