Submission #2167584
Source Code Expand
#include <iostream> #include <vector> #include <utility> #define inf 1000000000 using namespace std; struct edge{ int to, cap, rev; edge(int a, int b, int c){ to = a, cap = b, rev = c; } }; int N; vector<int> tree[100005]; int depth[100005]; vector<edge> G[205]; int S, T; bool used[205]; void dfs2(int v, int prev, int dep) { depth[v] = dep; for(int i = 0; i < tree[v].size(); i++){ if(tree[v][i] != prev) dfs2(tree[v][i], v, dep+1); } } int dfs(int v, int f) { used[v] = true; if(v == T) return f; int ret; for(int i = 0; i < G[v].size(); i++){ if(used[G[v][i].to] || G[v][i].cap <= 0) continue; ret = dfs(G[v][i].to, min(f, G[v][i].cap)); if(ret > 0){ G[v][i].cap -= ret; G[G[v][i].to][G[v][i].rev].cap += ret; return ret; } } return 0; } void add_edge(int s, int t, int cap) { G[s].push_back(edge(t, cap, G[t].size())); G[t].push_back(edge(s, 0, G[s].size()-1)); } int main(void) { cin >> N; int a, b; for(int i = 0; i < N-1; i++){ cin >> a >> b; tree[a].push_back(b); tree[b].push_back(a); } S = N+1, T = N+2; dfs2(1, -1, 0); for(int i = 1; i <= N; i++){ if(depth[i] % 2){ add_edge(S, i, 1); for(int j = 0; j < tree[i].size(); j++) add_edge(i, tree[i][j], 1); } else add_edge(i, T, 1); } int ans = 0, flow; while(1){ for(int i = 1; i <= T; i++) used[i] = false; flow = dfs(S, inf); if(flow <= 0) break; ans += flow; } if(N % 2 == 0 && ans == N/2) cout << "Second" << endl; else cout << "First" << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Black and White Tree |
User | leaf1415 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1593 Byte |
Status | RE |
Exec Time | 207 ms |
Memory | 6272 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | RE | 187 ms | 6272 KB |
in10.txt | RE | 186 ms | 6272 KB |
in11.txt | RE | 187 ms | 6144 KB |
in12.txt | RE | 106 ms | 2944 KB |
in13.txt | RE | 186 ms | 6144 KB |
in14.txt | RE | 189 ms | 6144 KB |
in15.txt | RE | 187 ms | 6144 KB |
in16.txt | RE | 186 ms | 6144 KB |
in17.txt | RE | 187 ms | 6144 KB |
in18.txt | RE | 188 ms | 6144 KB |
in19.txt | RE | 185 ms | 6144 KB |
in2.txt | RE | 188 ms | 6272 KB |
in20.txt | RE | 187 ms | 6144 KB |
in21.txt | RE | 188 ms | 6272 KB |
in22.txt | RE | 187 ms | 6272 KB |
in23.txt | RE | 190 ms | 6144 KB |
in24.txt | RE | 186 ms | 6144 KB |
in25.txt | RE | 188 ms | 6144 KB |
in26.txt | RE | 187 ms | 6144 KB |
in27.txt | RE | 190 ms | 6144 KB |
in28.txt | AC | 2 ms | 2560 KB |
in29.txt | RE | 188 ms | 6144 KB |
in3.txt | RE | 187 ms | 6272 KB |
in30.txt | RE | 186 ms | 6144 KB |
in31.txt | RE | 188 ms | 6144 KB |
in32.txt | RE | 186 ms | 6144 KB |
in33.txt | RE | 207 ms | 6144 KB |
in4.txt | RE | 196 ms | 6272 KB |
in5.txt | RE | 194 ms | 6272 KB |
in6.txt | RE | 191 ms | 6272 KB |
in7.txt | RE | 204 ms | 6272 KB |
in8.txt | RE | 201 ms | 6272 KB |
in9.txt | RE | 190 ms | 6272 KB |
sample1.txt | AC | 2 ms | 2560 KB |
sample2.txt | AC | 2 ms | 2560 KB |
sample3.txt | AC | 2 ms | 2560 KB |