Submission #2210304
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<int> g[N]; int st[N], dr[N]; bool f[N], red[N]; int n; static void dfs(int u, int far = 0) { for (auto v: g[u]) if (v != far) { red[v] = red[u] ^ true; dfs(v, u); } } static bool pairup(int u) { if (f[u]) return false; f[u] = true; for (auto v: g[u]) if (!dr[v]) { st[u] = v; dr[v] = u; return true; } for (auto v: g[u]) if (pairup(dr[v])) { st[u] = v; dr[v] = u; return true; } return false; } int main() { #ifdef HOME freopen("agc14d.in", "r", stdin); freopen("agc14d.out", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int matching(0); bool flag; cin >> n; for (int a, b, i = 1; i < n; ++i) { cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } if (n % 2) { cout << "First\n"; return 0; } dfs(1); do { flag = false; for (int i = 1; i <= n; ++i) if (red[i]) { if (!st[i] && pairup(i)) { flag = true; matching+= 1; } } memset(f, 0x00, sizeof f); } while (flag); cout << (matching == n / 2 ? "Second" : "First") << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Black and White Tree |
User | anai |
Language | C++14 (GCC 5.4.1) |
Score | 900 |
Code Size | 1193 Byte |
Status | AC |
Exec Time | 46 ms |
Memory | 6784 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 900 / 900 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 45 ms | 6784 KB |
in10.txt | AC | 45 ms | 6784 KB |
in11.txt | AC | 45 ms | 6784 KB |
in12.txt | AC | 6 ms | 3072 KB |
in13.txt | AC | 45 ms | 6784 KB |
in14.txt | AC | 45 ms | 6784 KB |
in15.txt | AC | 45 ms | 6784 KB |
in16.txt | AC | 46 ms | 6784 KB |
in17.txt | AC | 45 ms | 6784 KB |
in18.txt | AC | 46 ms | 6784 KB |
in19.txt | AC | 46 ms | 6784 KB |
in2.txt | AC | 44 ms | 6784 KB |
in20.txt | AC | 46 ms | 6784 KB |
in21.txt | AC | 44 ms | 6784 KB |
in22.txt | AC | 44 ms | 6784 KB |
in23.txt | AC | 45 ms | 6784 KB |
in24.txt | AC | 45 ms | 6784 KB |
in25.txt | AC | 45 ms | 6784 KB |
in26.txt | AC | 45 ms | 6784 KB |
in27.txt | AC | 46 ms | 6784 KB |
in28.txt | AC | 2 ms | 2688 KB |
in29.txt | AC | 34 ms | 5760 KB |
in3.txt | AC | 44 ms | 6784 KB |
in30.txt | AC | 33 ms | 5760 KB |
in31.txt | AC | 45 ms | 6784 KB |
in32.txt | AC | 45 ms | 6784 KB |
in33.txt | AC | 45 ms | 6784 KB |
in4.txt | AC | 44 ms | 6784 KB |
in5.txt | AC | 44 ms | 6784 KB |
in6.txt | AC | 34 ms | 5888 KB |
in7.txt | AC | 46 ms | 6784 KB |
in8.txt | AC | 45 ms | 6784 KB |
in9.txt | AC | 44 ms | 6784 KB |
sample1.txt | AC | 2 ms | 2560 KB |
sample2.txt | AC | 2 ms | 2688 KB |
sample3.txt | AC | 2 ms | 2688 KB |