Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- std::vector<std::vector<int>> G;
- bool dfs( int v, bool turn )
- {
- bool nikuda = true, can_win = false;
- for (auto & i : G[v])
- can_win = (turn == dfs(i, !turn)) || can_win, nikuda = false;
- return nikuda ? !turn : (can_win && turn);
- }
- int main()
- {
- int m, n, s, a, b;
- FILE *In = fopen("game.in", "r"), *Out = fopen("game.out", "w");
- fscanf(In, "%i%i%i", &n, &m, &s);
- G.resize(n);
- while (m--)
- fscanf(In, "%i%i", &a, &b), G[--a].push_back(--b);
- fprintf(Out, dfs(--s, false) ? "Second player wins" : "First player wins");
- fclose(In);
- fclose(Out);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement