結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
12,936 KB
testcase_01 AC 4 ms
13,060 KB
testcase_02 AC 3 ms
6,044 KB
testcase_03 AC 4 ms
5,932 KB
testcase_04 AC 5 ms
5,940 KB
testcase_05 AC 4 ms
5,932 KB
testcase_06 AC 4 ms
5,924 KB
testcase_07 AC 106 ms
7,936 KB
testcase_08 AC 53 ms
7,008 KB
testcase_09 AC 63 ms
7,208 KB
testcase_10 AC 46 ms
6,908 KB
testcase_11 AC 173 ms
9,048 KB
testcase_12 AC 180 ms
9,048 KB
testcase_13 AC 169 ms
8,932 KB
testcase_14 AC 168 ms
8,928 KB
testcase_15 AC 185 ms
9,116 KB
testcase_16 AC 184 ms
9,124 KB
testcase_17 AC 190 ms
9,188 KB
testcase_18 AC 193 ms
9,868 KB
testcase_19 AC 187 ms
9,752 KB
testcase_20 AC 184 ms
9,752 KB
testcase_21 AC 178 ms
9,488 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];

bool dfs(int idx, int par) {
  for(auto &to : g[idx]) {
    if(to == par) continue;
    if(!dfs(to, idx)) return true;
  }
  return 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