-
Notifications
You must be signed in to change notification settings - Fork 5
/
M.cpp
68 lines (61 loc) · 1.25 KB
/
M.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
string fileName = "game";
ofstream out(fileName + ".out");
ifstream in(fileName + ".in");
int n, m, s;
unsigned int MAX_N = 100000;
vector<vector<int>> edges(MAX_N);
vector<int> color(MAX_N, 0);
vector<bool> was(MAX_N, false);
vector<int> component;
vector<int> components(MAX_N, 0);
vector<int> order;
int ans = 0;
vector<int> path(MAX_N, -1);
int start, finish;
int ans1 = 0, ans2 = 0;
string as = "Second player wins";
enum token {
first, second
};
void input() {
in >> n >> m >> s;
--s;
for (int i = 0; i < m; ++i) {
int x, y;
in >> x >> y;
edges[x - 1].push_back(y - 1);
}
}
void output() {
out << as;
}
bool check(int to){
return edges[to].size() == 0;
}
void dfs(int v, token e) {
//was[v] = true;
for (auto to: edges[v]) {
if (!was[to]) {
if (e == first && check(to)) as = "First player wins";
else {
if (e == first) dfs(to, second);
else dfs(to, first);
}
}
}
}
void solve() {
if(!check(s)) dfs(s, first);
else as = "Second player wins";
}
int main() {
input();
solve();
output();
return 0;
}