Submission #1751509


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9, INF = 0x3f3f3f3f;

struct Edge {
	int to, res;
	Edge *next;
	Edge () {}
	Edge (int to, int res, Edge *next) : to(to), res(res), next(next) {}
}*head[N], pool[N << 2], *pis = pool, *cur[N];

void AddEdge (int u, int v, int c) {
	head[u] = new (pis++) Edge(v, c, head[u]);
	head[v] = new (pis++) Edge(u, c, head[v]);
}

int s, t, d[N];

int Dfs (int u, int f) {
	if (u == t || f == 0) return f;
	int fellow = 0, D;
	for (Edge *&now = cur[u]; now; now = now -> next) if (d[now -> to] == d[u] + 1 && (D = Dfs(now -> to, min(now -> res, f)))) {
		fellow += D; now -> res -= D;
		(pool + ((now - pool) ^ 1)) -> res += D; f -= D;
		if (!f) break;
	}
	return fellow;
}

queue<int>Q;
bool vis[N];

bool Bfs () {
	memset(vis, 0, sizeof vis);
	Q.push(s); d[s] = 0; vis[s] = 1; int u;
	while (!Q.empty()) {
		u = Q.front(); Q.pop();
		for (Edge *now = head[u]; now; now = now -> next) if (now -> res && !vis[now -> to]) {
			d[now -> to] = d[u] + 1;
			vis[now -> to] = 1;
			Q.push(now -> to);
		}
	}
	return vis[t];
}

int n;

void Dfs (int u, int fa, bool o) {
	if (o) AddEdge(s, u, 1); else AddEdge(u, t, 1);
	o ^= 1; for (Edge *now = head[u]; now; now = now -> next) if (now -> to != fa && now -> to != s && now -> to != t) Dfs(now -> to, u, o);
}

int main () {
	scanf("%d", &n); s = n + 1; t = s + 1;
	for (int i = 1, u, v; i < n; ++i) scanf("%d%d", &u, &v), AddEdge(u, v, 1);
	Dfs(1, 0, 0);
	int fellow = 0;
	while (Bfs()) {
		for (int i = 1; i <= t; ++i) cur[i] = head[i];
		fellow += Dfs(s, INF);
	}
//	printf("%d\n", fellow);
	puts((fellow << 1) == n ? "Second" : "First");
	return 0;
}

Submission Info

Submission Time
Task D - Black and White Tree
User DraZxlNDdt
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1718 Byte
Status AC
Exec Time 119 ms
Memory 8704 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:55:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n); s = n + 1; t = s + 1;
                 ^
./Main.cpp:56:75: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1, u, v; i < n; ++i) scanf("%d%d", &u, &v), AddEdge(u, v, 1);
                                                                           ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 3
AC × 39
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 100 ms 8704 KB
in10.txt AC 98 ms 8704 KB
in11.txt AC 118 ms 8704 KB
in12.txt AC 10 ms 3200 KB
in13.txt AC 105 ms 8704 KB
in14.txt AC 104 ms 8704 KB
in15.txt AC 119 ms 8704 KB
in16.txt AC 118 ms 8704 KB
in17.txt AC 119 ms 8704 KB
in18.txt AC 116 ms 8704 KB
in19.txt AC 117 ms 8704 KB
in2.txt AC 100 ms 8704 KB
in20.txt AC 109 ms 8704 KB
in21.txt AC 99 ms 8704 KB
in22.txt AC 99 ms 8704 KB
in23.txt AC 111 ms 8704 KB
in24.txt AC 103 ms 8704 KB
in25.txt AC 116 ms 8704 KB
in26.txt AC 115 ms 8704 KB
in27.txt AC 106 ms 8704 KB
in28.txt AC 2 ms 2432 KB
in29.txt AC 116 ms 8704 KB
in3.txt AC 99 ms 8704 KB
in30.txt AC 110 ms 8704 KB
in31.txt AC 112 ms 8704 KB
in32.txt AC 106 ms 8704 KB
in33.txt AC 115 ms 8704 KB
in4.txt AC 100 ms 8704 KB
in5.txt AC 100 ms 8704 KB
in6.txt AC 93 ms 8704 KB
in7.txt AC 92 ms 8704 KB
in8.txt AC 99 ms 8704 KB
in9.txt AC 100 ms 8704 KB
sample1.txt AC 2 ms 2432 KB
sample2.txt AC 2 ms 2432 KB
sample3.txt AC 2 ms 2432 KB