Advertisement
gertsog

Ash

Nov 10th, 2019
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. std::vector<std::vector<int>> G;
  5.  
  6. bool dfs( int v, bool turn )
  7. {
  8.   bool nikuda = true, can_win = false;
  9.  
  10.   for (auto & i : G[v])
  11.     can_win = (turn == dfs(i, !turn)) || can_win, nikuda = false;
  12.  
  13.   return nikuda ? !turn : (can_win && turn);
  14. }
  15.  
  16. int main()
  17. {
  18.   int m, n, s, a, b;
  19.   FILE *In = fopen("game.in", "r"), *Out = fopen("game.out", "w");
  20.  
  21.   fscanf(In, "%i%i%i", &n, &m, &s);
  22.  
  23.   G.resize(n);
  24.  
  25.   while (m--)
  26.     fscanf(In, "%i%i", &a, &b), G[--a].push_back(--b);
  27.  
  28.   fprintf(Out, dfs(--s, false) ? "Second player wins" : "First player wins");
  29.  
  30.   fclose(In);
  31.   fclose(Out);
  32.  
  33.   return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement