#P17195. [KOI 2026 #2] 游戏

[KOI 2026 #2] 游戏

Problem Description

Alice and Bob are going to play a game in a maze consisting of NN rooms and corridors connecting these rooms.

The rooms in the maze are numbered 1,2,⋯ ,N1,2,\cdots,N. Some rooms have exits: if room ii (1≤i≤N1 \le i \le N) has an exit, then Ai=1A_i=1; otherwise Ai=0A_i=0.

The corridors in the maze connect exactly MM pairs of rooms. There may be multiple corridors connecting the same pair of rooms.

Specifically, for each ii (1≤i≤M1 \le i \le M), there are cic_i distinct corridors connecting room aia_i and room bib_i.

Note that it is not guaranteed that every pair of rooms is mutually reachable through corridors.

Alice and Bob will play a total of QQ games. Game jj (1≤j≤Q1 \le j \le Q) is played as follows:

  • Alice enters room sjs_j of the maze.
  • Alice may move to an adjacent room according to the following rules.
    • Suppose Alice is currently in room xx. Alice chooses kjk_j distinct corridors that are connected to room xx. Even if they connect the same pair of rooms, she may choose multiple different corridors. If there are fewer than kjk_j corridors connected to room xx, Alice loses the game and the game ends immediately.
    • After Alice makes her choice, Bob chooses one corridor from the kjk_j corridors Alice selected.
    • Alice moves along the corridor chosen by Bob to the room at the other end.
  • Alice repeats the process of moving to another room according to the rules above any number of times (including 00 times). As soon as she reaches a room with an exit, she wins the game.

If room sjs_j has an exit, then the room where Alice starts already has an exit, so Alice can win immediately.

Alice will do her best to win, and Bob will do his best to prevent Alice from winning. That is, if no matter how Bob chooses during the game, Alice can make appropriate choices at every step and eventually reach a room with an exit, then Alice wins; otherwise she cannot win.

For each game, determine whether Alice can win.

Input Format

The first line contains three integers NN, MM, and QQ separated by spaces, representing the number of rooms in the maze, the number of corridor types, and the number of games Alice and Bob will play.

The second line contains NN integers A1,A2,⋯ ,ANA_1,A_2,\cdots,A_N separated by spaces.

The next MM lines describe the corridors. Line ii (1≤i≤M1 \le i \le M) contains three integers ai,bi,cia_i,b_i,c_i separated by spaces, meaning there are cic_i corridors connecting room aia_i and room bib_i.

The next QQ lines describe the QQ games Alice and Bob will play. Line jj (1≤j≤Q1 \le j \le Q) contains two integers sjs_j and kjk_j separated by spaces.

Output Format

Output QQ lines of answers starting from the first line. In line jj (1≤j≤Q1 \le j \le Q), output YES if Alice can win game jj, otherwise output NO.

5 5 5
0 0 1 0 0
1 2 1
1 3 1
1 4 2
2 3 2
3 4 1
2 1
1 2
3 3
4 4
5 1
YES
YES
YES
NO
NO
4 3 4
1 0 0 0
1 2 2
2 3 3
3 4 1
1 3
2 2
3 3
4 1
YES
YES
NO
YES
4 3 3
0 1 1 0
1 2 1
1 3 3
1 4 2
4 2
1 3
4 3
YES
YES
NO
2 0 2
1 0
1 1
2 1
YES
NO

Hint

Explanation of Sample 1

In this sample, the maze has 55 rooms and 77 corridors, and only room 33 has an exit. Alice and Bob play 55 games in total.

In the first game, Alice starts in room 22, and she needs to choose 11 corridor when moving. Alice first chooses a corridor leading to room 33, and Bob can only choose that corridor. Therefore, Alice moves to room 33, which has an exit, and wins the game.

In the second game, Alice starts in room 11, and she needs to choose 22 corridors when moving. Alice can win with the following strategy:

  • First, choose one corridor leading to room 22 and one corridor leading to room 33, respectively.
    • If Bob chooses the corridor leading to room 33, since room 33 has an exit, Alice wins.
    • Suppose Bob chooses the corridor leading to room 22. Then Alice chooses two corridors leading to room 33. Bob must choose one of them, so Alice moves to room 33 and wins.

Therefore, no matter how Bob chooses, Alice will eventually move to room 33, which has an exit, and win.

In the third game, Alice starts in room 33, and she needs to choose 33 corridors when moving. Since room 33 has an exit, Alice can win without making any move.

In the fourth game, Alice starts in room 44, and she needs to choose 44 corridors when moving. However, among the corridors connected to room 44, there are 22 corridors leading to room 11 and 11 corridor leading to room 33, for a total of only 33 corridors. Therefore, Alice cannot move and cannot win.

In the fifth game, Alice starts in room 55, and she needs to choose 11 corridor when moving. Room 55 has no exit and is not connected by any corridor, so she cannot move to any other room. Thus, Alice cannot win.

Explanation of Sample 2

In the third game, Alice starts from room 33, and she needs to choose 33 corridors when moving. At this time, Bob can prevent Alice from winning with the following strategy:

  • If among the corridors Alice chooses, there is at least one leading to room 44, Bob chooses that corridor. Then Alice moves to room 44. Since room 44 is connected by only one corridor, Alice cannot continue moving, so she cannot win.
  • If Alice does not choose any corridor leading to room 44, then she can only choose three corridors leading to room 22. Bob then chooses a corridor leading to room 22, and Alice moves to room 22.
  • Among the corridors connected to room 22, there are 22 corridors leading to room 11. In order to move, Alice must choose a corridor leading to room 33. At this time, Bob also chooses the corridor leading to room 33, making Alice return to room 33 again.

Before Alice enters room 44, Bob can keep repeating the strategy above. Therefore, no matter how many times Alice moves, she cannot reach the only room with an exit, room 11, and thus cannot win.

Constraints

  • All given values are integers.
  • 1≤N≤200 0001 \le N \le 200\,000
  • 0≤M≤400 0000 \le M \le 400\,000
  • 1≤Q≤200 0001 \le Q \le 200\,000
  • For each integer ii (1≤i≤N1 \le i \le N), AiA_i is 00 or 11.
  • For each integer ii (1≤i≤M1 \le i \le M), 1≤ai<bi≤N1 \le a_i<b_i \le N.
  • For any two distinct integers i,ji,j (1≤i,j≤M1 \le i,j \le M), ai≠aja_i \ne a_j or bi≠bjb_i \ne b_j.
  • For each integer ii (1≤i≤M1 \le i \le M), 1≤ci≤1 000 000 0001 \le c_i \le 1\,000\,000\,000.
  • For each integer jj (1≤j≤Q1 \le j \le Q), 1≤sj≤N1 \le s_j \le N.
  • For each integer jj (1≤j≤Q1 \le j \le Q), 1≤kj≤1 000 000 000 000 000 0001 \le k_j \le 1\,000\,000\,000\,000\,000\,000.

Subtasks

  1. (66 points) M=N−1M=N-1; for each integer ii (1≤i≤M1 \le i \le M), ai=ia_i=i and bi=i+1b_i=i+1. Only room 11 has an exit, i.e. A1=1A_1=1 and A2=A3=⋯=AN=0A_2=A_3=\cdots=A_N=0.
  2. (88 points) M=N−1M=N-1; for each integer ii (1≤i≤M1 \le i \le M), ai=1a_i=1 and bi=i+1b_i=i+1.
  3. (77 points) k1=k2=⋯=kQ=1k_1=k_2=\cdots=k_Q=1.
  4. (1414 points) k1=k2=⋯=kQk_1=k_2=\cdots=k_Q.
  5. (1515 points) s1=s2=⋯=sQs_1=s_2=\cdots=s_Q.
  6. (1616 points) N≤3 000N \le 3\,000, M≤3 000M \le 3\,000; for each integer jj (1≤j≤Q1 \le j \le Q), kj≤3 000k_j \le 3\,000.
  7. (3434 points) No additional constraints.

Translated by ChatGPT-5.6.

Translated by ChatGPT 5