Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.25 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.io.PrintWriter;
  7. import java.util.ArrayList;
  8. import java.util.Collections;
  9. import java.util.GregorianCalendar;
  10. import java.util.PriorityQueue;
  11. import java.util.StringTokenizer;
  12.  
  13. public class D {
  14.     static BufferedReader in;
  15.     static StringTokenizer st;
  16.     static PrintWriter out;
  17.  
  18.     ArrayList<Integer> graph[];
  19.     int n;
  20.     boolean answer;
  21.  
  22.     public void Solution() throws IOException {
  23.         n = nextInt();
  24.         int m = nextInt();
  25.         int start = nextInt() - 1;
  26.         graph = new ArrayList[n];
  27.         for (int i = 0; i < n; i++) {
  28.             graph[i] = new ArrayList<Integer>();
  29.         }
  30.         for (int i = 0; i < m; i++) {
  31.             int a = nextInt() - 1;
  32.             int b = nextInt() - 1;
  33.             graph[a].add(b);
  34.         }
  35.         if (dfs(start) == true) {
  36.             out.println("First player wins");
  37.         } else {
  38.             out.println("Second player wins");
  39.         }
  40.  
  41.     }
  42.  
  43.     public boolean dfs(int v) {
  44.         answer = false;
  45.         for (int i : graph[v]) {
  46.             if (!dfs(i)) {
  47.                 answer = true;
  48.             }
  49.         }
  50.         return answer;
  51.     }
  52.  
  53.     public void run() throws IOException {
  54.         try {
  55.             in = new BufferedReader(new FileReader(new File("game.in")));
  56.             out = new PrintWriter(new File("game.out"));
  57.             // in = new BufferedReader(new InputStreamReader(System.in));
  58.             // out = new PrintWriter(System.out);
  59.             Solution();
  60.             out.close();
  61.  
  62.         } catch (Exception e) {
  63.             e.printStackTrace();
  64.             System.exit(261);
  65.         }
  66.     }
  67.  
  68.     public String nextToken() throws IOException {
  69.         if (st == null || !st.hasMoreTokens()) {
  70.             st = new StringTokenizer(in.readLine());
  71.         }
  72.         return st.nextToken();
  73.     }
  74.  
  75.     static boolean hasNextToken() throws IOException {
  76.         while (st == null || !st.hasMoreTokens()) {
  77.             String line = in.readLine();
  78.             if (line == null) {
  79.                 return false;
  80.             }
  81.             st = new StringTokenizer(line);
  82.         }
  83.         return true;
  84.     }
  85.  
  86.     public long nextlong() throws IOException {
  87.         return Long.parseLong(nextToken());
  88.     }
  89.  
  90.     public int nextInt() throws IOException {
  91.         return Integer.parseInt(nextToken());
  92.     }
  93.  
  94.     public double nextDouble() throws IOException {
  95.         return Double.parseDouble(nextToken());
  96.     }
  97.  
  98.     public static void main(String args[]) throws IOException {
  99.         new D().run();
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement