From 4919169d97ee5eea97e0a25e7ffb1a89804096a7 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Wed, 6 Oct 2021 10:07:21 +0800 Subject: [PATCH] D - Black and White Tree https://atcoder.jp/contests/agc014/submissions/26377341 --- AtCoder/AGC014/D/D.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 AtCoder/AGC014/D/D.cpp diff --git a/AtCoder/AGC014/D/D.cpp b/AtCoder/AGC014/D/D.cpp new file mode 100644 index 00000000..65a8d140 --- /dev/null +++ b/AtCoder/AGC014/D/D.cpp @@ -0,0 +1,33 @@ +#include + +using namespace std; + +int n, u, v; +vector g[100005]; +bool flag, vis[100005]; + +void dfs(int u, int f) { + if (flag) return; + for (int i : g[u]) { + if (i != f) dfs(i, u); + } + if (!vis[u]) { + if (f == -1 || vis[f]) { + flag = true; + } else { + vis[f] = vis[u] = true; + } + } +} + +int main() { + cin >> n; + for (int i = 1; i < n; i++) { + cin >> u >> v; + g[u].push_back(v); + g[v].push_back(u); + } + dfs(1, -1); + cout << (flag ? "First" : "Second") << endl; + return 0; +}