結果
問題 | No.768 Tapris and Noel play the game on Treeone |
ユーザー |
|
提出日時 | 2018-12-16 11:56:45 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 209 ms / 2,000 ms |
コード長 | 1,791 bytes |
コンパイル時間 | 948 ms |
コンパイル使用メモリ | 102,792 KB |
実行使用メモリ | 19,436 KB |
最終ジャッジ日時 | 2024-09-25 06:27:09 |
合計ジャッジ時間 | 4,223 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
#include <algorithm>#include <cassert>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <ctime>#include <deque>#include <functional>#include <iomanip>#include <iostream>#include <list>#include <map>#include <queue>#include <random>#include <set>#include <sstream>#include <string>#include <utility>#include <vector>#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)#define DEBUGP(val) cerr << #val << "=" << val << "\n"using namespace std;typedef long long int ll;typedef vector<int> VI;typedef vector<ll> VL;typedef pair<int, int> PI;const int N = 100100;VI g[N];set<int> dp[N]; // children that players are able to win onint dp_par[N];int dfs1(int v, int par) {int can_win = 1;for (int w: g[v]) {if (par == w) continue;int res = dfs1(w, v);if (res == 1) {dp[v].insert(w);}can_win &= 1 - res;}return can_win;}void dfs2(int v, int par, int par_result) {for (int w: g[v]) {if (par == w) continue;bool incl = 0;if (dp[v].size() == 0 || (dp[v].size() == 1 && dp[v].count(w))) {incl = 1;}dfs2(w, v, incl && !par_result);}dp_par[v] = par_result;}int main(void) {ios::sync_with_stdio(false);cin.tie(0);int n;cin >> n;REP(i, 0, n - 1) {int a, b;cin >> a >> b;a--, b--;g[a].push_back(b);g[b].push_back(a);}dfs1(0, -1);dfs2(0, -1, 0);VI can_win;REP(i, 0, n) {if (dp[i].size() == 0 && dp_par[i] == 0) {can_win.push_back(i);}}if (0) {REP(i, 0, n) {cerr << "dp[" << i << "]:";for (int w: dp[i]) cerr << " " << w;cerr << endl;DEBUGP(dp_par[i]);}}cout << can_win.size() << endl;for (int v: can_win) cout << v + 1 << endl;}