luogu#P11280. 「GFOI Round 2」Jom & Terry

    ID: 9980 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>洛谷原创O2优化图遍历最短路洛谷月赛

「GFOI Round 2」Jom & Terry

Background

I am solving #3406. 「2020-2021 集训队作业」Tom & Jerry......

You are right, but:

Tom and Jerry is an American animated media franchise and series of comedy short films created in 1940 by William Hanna and Joseph Barbera. Best known for its 161 theatrical short films by Metro-Goldwyn-Mayer, the series centers on the rivalry between the titular characters of a cat named Tom and a mouse named Jerry. Many shorts also feature several recurring characters.

In its original run, Hanna and Barbera produced 114 Tom and Jerry shorts for MGM from 1940 to 1958. During this time, they won seven Academy Awards for Best Animated Short Film, tying for first place with Walt Disney's Silly Symphonies with the most awards in the category. After the MGM cartoon studio closed in 1957, MGM revived the series with Gene Deitch directing an additional 13 Tom and Jerry shorts for Rembrandt Films from 1961 to 1962. Tom and Jerry became the highest-grossing animated short film series of that time, overtaking Looney Tunes. Chuck Jones produced another 34 shorts with Sib Tower 12 Productions between 1963 and 1967. Five more shorts have been produced since 2001, making a total of 166 shorts.

A number of spin-offs have been made, including the television series The Tom and Jerry Show (1975), The Tom and Jerry Comedy Show (1980–1982), Tom & Jerry Kids (1990–1993), Tom and Jerry Tales (2006–2008), and The Tom and Jerry Show (2014–2021). In 1992, the first feature-length film based on the series, Tom and Jerry: The Movie, was released. 13 direct-to-video films have been produced since 2002. In 2021, a a live-action/animated hybrid film was released. In 2019, a musical adaptation of the series, titled Tom and Jerry: Purr-Chance to Dream, debuted in Japan, in advance of Tom and Jerry's 80th anniversary.

Problem Description

Terry and Jom are playing a game on an undirected connected graph with nn nodes and mm edges, which has a designated "root" node rr. 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 uu within the same turn, as long as Terry goes there first).

Given qq queries, each specifying the starting positions aa and bb of Terry and Jom respectively, determine whether Terry can reach the root node rr.

Input Format

The first line contains three integers nn, mm, and rr, representing the number of nodes, the number of edges, and the index of the root, respectively.

The next mm lines each contain two integers (u,v)(u, v), representing an edge between nodes uu and vv (Note that there may contain multiple edges and self-loops).

The following line contains a single integer qq, representing the number of queries.

The next qq lines each contain two integers aa and bb, 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 ii-th line of the next qq lines, print Terry if Terry can reach the root in the ii-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 n,m,qn, m, q \le Special Properties Score
00 10610^6 A 11
11 1010 No 99
22 10610^6 B 1515
33 C
44 No 6060
  • Special Property A: q=0q = 0.
  • Special Property B: The graph is a chain.
  • Special Property C: The graph is a star graph.

For all tests, it is guaranteed that:

  • 1n,m1061 \le n, m \le 10^6;
  • 0q1060 \le q \le 10^6;
  • 1r,u,v,a,bn1 \le r, u, v, a, b \le n;
  • The given graph is an undirected connected graph.