#P11280. 「GFOI Round 2」Jom & Terry
「GFOI Round 2」Jom & Terry
Description
Terry and Jom are playing a game on an undirected connected graph with nodes and edges, which has a designated "root" node . The game follows these rules:
- Terry moves first.
- The two players take turns moving along the edges of the graph, with each move traversing one edge (or they can choose to "rest" and do nothing).
- Terry cannot move to the node where Jom is currently located (Terry is only considered "caught" if he voluntarily moves to the same node as Jom; it is allowed for both to move to the same node within the same turn, as long as Terry goes there first).
Given queries, each specifying the starting positions and of Terry and Jom respectively, determine whether Terry can reach the root node .
Input Format
The first line contains three integers , , and , representing the number of nodes, the number of edges, and the index of the root, respectively.
The next lines each contain two integers , representing an edge between nodes and (Note that there may contain multiple edges and self-loops).
The following line contains a single integer , representing the number of queries.
The next lines each contain two integers and , representing the starting positions of Terry and Jom, respectively.
Output Format
Since this is a warm-up problem, you should print I'm here! at the beginning.
For the -th line of the next lines, print Terry if Terry can reach the root in the -th query; otherwise, print Jom.
5 4 3
4 3
3 2
1 5
1 2
2
1 2
5 4
I'm here!
Jom
Jom
5 5 4
1 4
4 3
3 2
4 5
5 3
2
3 1
5 1
I'm here!
Terry
Terry
Hint
Subtasks and Constraints
| Subtask ID | Special Properties | Score | |
|---|---|---|---|
| A | |||
| No | |||
| B | |||
| C | |||
| No |
- Special Property A: .
- Special Property B: The graph is a chain.
- Special Property C: The graph is a star graph.
For all tests, it is guaranteed that:
- ;
- ;
- ;
- The given graph is an undirected connected graph.
京公网安备 11011102002149号