結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー ei1333333
提出日時 2018-12-16 18:33:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 650 bytes
コンパイル時間 2,557 ms
コンパイル使用メモリ 201,652 KB
最終ジャッジ日時 2025-01-06 19:37:08
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

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