Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.GregorianCalendar;
- import java.util.PriorityQueue;
- import java.util.StringTokenizer;
- public class D {
- static BufferedReader in;
- static StringTokenizer st;
- static PrintWriter out;
- ArrayList<Integer> graph[];
- int n;
- boolean answer;
- public void Solution() throws IOException {
- n = nextInt();
- int m = nextInt();
- int start = nextInt() - 1;
- graph = new ArrayList[n];
- for (int i = 0; i < n; i++) {
- graph[i] = new ArrayList<Integer>();
- }
- for (int i = 0; i < m; i++) {
- int a = nextInt() - 1;
- int b = nextInt() - 1;
- graph[a].add(b);
- }
- if (dfs(start) == true) {
- out.println("First player wins");
- } else {
- out.println("Second player wins");
- }
- }
- public boolean dfs(int v) {
- answer = false;
- for (int i : graph[v]) {
- if (!dfs(i)) {
- answer = true;
- }
- }
- return answer;
- }
- public void run() throws IOException {
- try {
- in = new BufferedReader(new FileReader(new File("game.in")));
- out = new PrintWriter(new File("game.out"));
- // in = new BufferedReader(new InputStreamReader(System.in));
- // out = new PrintWriter(System.out);
- Solution();
- out.close();
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(261);
- }
- }
- public String nextToken() throws IOException {
- if (st == null || !st.hasMoreTokens()) {
- st = new StringTokenizer(in.readLine());
- }
- return st.nextToken();
- }
- static boolean hasNextToken() throws IOException {
- while (st == null || !st.hasMoreTokens()) {
- String line = in.readLine();
- if (line == null) {
- return false;
- }
- st = new StringTokenizer(line);
- }
- return true;
- }
- public long nextlong() throws IOException {
- return Long.parseLong(nextToken());
- }
- public int nextInt() throws IOException {
- return Integer.parseInt(nextToken());
- }
- public double nextDouble() throws IOException {
- return Double.parseDouble(nextToken());
- }
- public static void main(String args[]) throws IOException {
- new D().run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement