結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー akun0716
提出日時 2020-04-05 14:59:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 2,238 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 89,192 KB
実行使用メモリ 11,540 KB
最終ジャッジ日時 2024-07-03 08:12:17
合計ジャッジ時間 4,831 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0