結果
問題 | No.768 Tapris and Noel play the game on Treeone |
ユーザー | akun0716 |
提出日時 | 2020-04-05 14:59:13 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 175 ms / 2,000 ms |
コード長 | 2,238 bytes |
コンパイル時間 | 906 ms |
コンパイル使用メモリ | 87,640 KB |
実行使用メモリ | 11,432 KB |
最終ジャッジ日時 | 2023-09-16 06:38:43 |
合計ジャッジ時間 | 5,549 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,384 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 65 ms
7,828 KB |
testcase_08 | AC | 34 ms
5,648 KB |
testcase_09 | AC | 39 ms
5,952 KB |
testcase_10 | AC | 31 ms
5,312 KB |
testcase_11 | AC | 122 ms
10,352 KB |
testcase_12 | AC | 119 ms
10,396 KB |
testcase_13 | AC | 112 ms
10,152 KB |
testcase_14 | AC | 116 ms
10,208 KB |
testcase_15 | AC | 111 ms
10,488 KB |
testcase_16 | AC | 118 ms
10,504 KB |
testcase_17 | AC | 135 ms
10,664 KB |
testcase_18 | AC | 175 ms
11,432 KB |
testcase_19 | AC | 171 ms
11,168 KB |
testcase_20 | AC | 162 ms
10,828 KB |
testcase_21 | AC | 157 ms
10,196 KB |
20evil_special_uni1.txt | AC | 136 ms
10,584 KB |
20evil_special_uni2.txt | AC | 129 ms
10,256 KB |
ソースコード
#include <iostream> #include<vector> #include<algorithm> #include<string> #include<map> #include<set> #include<stack> #include<queue> #include<math.h> using namespace std; typedef long long ll; #define int long long typedef vector<int> VI; typedef pair<int, int> pii; typedef vector<pii> VP; typedef vector<string> VS; typedef priority_queue<int> PQ; template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fore(i,a) for(auto &i:a) #define REP(i,n) for(int i=0;i<n;i++) #define eREP(i,n) for(int i=0;i<=n;i++) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define eFOR(i,a,b) for(int i=(a);i<=(b);++i) #define SORT(c) sort((c).begin(),(c).end()) #define rSORT(c) sort((c).rbegin(),(c).rend()) #define LB(x,a) lower_bound((x).begin(),(x).end(),(a)) #define UB(x,a) upper_bound((x).begin(),(x).end(),(a)) #define INF 1000000000 #define LLINF 9223372036854775807 #define mod 1000000007 //priority_queue<int,vector<int>, greater<int> > q2; int N; vector<VI>G; bool dp[200010]; bool ans[200010]; int cnt[200010]; bool dfs(int now, int pa) { dp[now] = true; fore(to, G[now]) { if (to == pa)continue; if (dfs(to, now)) { dp[now] = false; cnt[now]++; } } return dp[now]; } void dfs1(int now, int pa) { //cout << now << " " << pa << endl; ans[now] = 1; fore(to, G[now])if (dp[to])ans[now] = false; VI wins; fore(to, G[now])if (dp[to]) { //cout << now << " " << to << endl; wins.push_back(to); } if (wins.size() == 0) { dp[now] = 1; fore(to, G[now])if (to != pa)dfs1(to, now); return; } else if (1 < wins.size()) { dp[now] = 0; fore(to, G[now])if (to != pa)dfs1(to, now); return; } else { fore(to, G[now])if (to != pa) { if (wins[0] == to)dp[now] = 1; else dp[now] = 0; dfs1(to, now); } return; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; G.resize(N); REP(i, N - 1) { int a, b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } dfs(0,-1); dfs1(0, -1); VI a; REP(i, N) { if (ans[i])a.push_back(i + 1); } cout << a.size() << endl; REP(i, a.size())cout << a[i] << endl; return 0; }