P26631 [AtCoder] Coins and Undirected Graph
NOI
题目描述

Problem Description

You are given an undirected graph with $ N $ vertices and $ M $ edges. Each vertex $ i $ ($0 \leq i < N$) has $ C_i $ coins on it. The length of each edge is $ 1 $.

Player 1 and Player 2 play a game to collect coins at vertex $ 0 $. Player 1 and Player 2 take turns repeating the following procedure alternately:

    1. Choose one vertex and denote it as $ j $.
    1. Among the vertices adjacent to vertex $ j $, choose one vertex $ k $ that is closer to vertex $ 0 $ than vertex $ j $.
    1. Move one or more coins from vertex $ j $ to vertex $ k $.

(Note) It is not allowed to choose vertex $ 0 $ or any vertex that cannot reach vertex $ 0 $ as $ j $.

Player 1 starts first, and the player who cannot move any coins loses.

Determine which player wins when both Player 1 and Player 2 play optimally.

Input Format

The input is given from the standard input in the following format:

$ N $ $ M $ $ C_0 $ $ ... $ $ C_{N-1} $ $ v_0 $ $ w_0 $ $ ... $ $ v_{M-1} $ $ w_{M-1} $

  • The first line contains the number of vertices $ N $ ($1 \leq N \leq 10^5$) and the number of edges $ M $ ($0 \leq M \leq 2*10^5$).
  • The second line contains the number of coins $ C_i $ ($0 \leq C_i \leq 10^8$) on each vertex $ i $ ($0 \leq i < N$) separated by spaces.
  • The $ 3+i $ line ($0 \leq i < M$) contains $ v_i $ ($0 \leq v_i < N$) and $ w_i $ ($0 \leq w_i < N$) separated by spaces, indicating that there is an undirected edge between vertex $ v_i $ and vertex $ w_i $.

Output Format

Output First if Player 1 wins.

Output Second if Player 2 wins.

Sample Input and Output

Sample Input #1

2 2
1 0
0 1
1 0

Sample Output #1

Second

Sample Input #2

2 2
0 1
0 1
1 0

Sample Output #2

First

Sample Input #3

4 3
0 0 1 1
1 0
2 1
3 1

Sample Output #3

Second

Sample Input #4

7 0
1 1 1 1 1 1 1

Sample Output #4

Second

Notes/Hints

Partial Points

  • If you solve the test cases where $N \leq 7$ and $C_0 + ... + C_{N-1} \leq 7$, you will be awarded $ 50 $ points.
  • If you solve all cases, you will be awarded $ 200 $ points.

Total $ 250 $ points

Sample Explanation 1

Since it is not possible to move the coins closer to vertex $ 0 $, Player 1 loses.

Sample Explanation 2

Move the coin from vertex $ 1 $ to vertex $ 0 $ and Player 1 wins.

Sample Explanation 3

No matter how Player 1 moves, Player 2 wins.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 2 1 0 0 1 1 0
样例输出
Second