#P8346. 「Wdoi-6」最澄澈的空与海

    ID: 9388 远端评测题 1000~3000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>搜索图论洛谷原创O2优化二分图洛谷月赛

「Wdoi-6」最澄澈的空与海

Background

The Hiroshige sped eastward with the two of them aboard. No noise, no shaking, just rushing eastward. Under the “Bankei-maku” device, even on the fully underground Boyo Tokaido, passengers could still enjoy the beautiful views of Mount Fuji and the Pacific Ocean.

However, the beautiful, very Japanese scenery seen from this Boyo Shinkansen “Hiroshige” was, to Merry, nothing more than boring visual stimulation. High dynamic range images or very Japanese scenery could not compare to the color of the real sky.

Body may fall like flowers, but the heart can drift far away like fragrance. Even if the body will one day wither like a flower, the heart can float to the distance like the scent of flowers.

"Merry, look, the stars in the sky."

Problem Description

Brief Statement

Given a bipartite graph with 2n2n vertices and mm edges (multiple edges may exist), where the left part and the right part have the same number of vertices, determine whether the number of its perfect matchings is exactly 11. If yes, output Renko; otherwise, output Merry.

Note: A perfect matching means selecting nn edges from the edge set such that the set of vertices incident to these edges covers exactly all 2n2n vertices.


Original Statement

At night, Renko and Merry came to the seaside in Tokyo. Lying on the beach, they admired the clear sky and sea, and counted the stars in the sky.

Among these stars, there are nn stars {ai}\{a_i\} that Renko found first, called Renko Stars; and there are also nn stars {bi}\{b_i\} that Merry found first, called Merry Stars. Since they were in sync, there is no intersection between these two sets of stars.

They discovered that some Renko Stars and some Merry Stars have exactly a motion relationship between them. Specifically, there are mm such relationships, each in the form (ui,vi)(u_i, v_i), meaning that the uiu_i-th Renko Star and the viv_i-th Merry Star have a motion relationship. These motion relationships may repeat.

This made Renko and Merry very curious. As a college girl majoring in super unified physics, Renko believed that if the motion of these stars is harmonious, then she should be able to pick some relationships from the mm motion relationships such that, while every star is included in these motion relationships, no star is included in two motion relationships at the same time.

However, Merry believed that harmonious motion might not exist. Moreover, even if Renko found such harmonious motion, she could not ensure the uniqueness of this harmonious motion. Two harmonious motions are different if and only if among the two selected sets of motion relationships, there exists at least one motion relationship that is not the same.

Because they could not agree, they flirt-argued for a while. Renko wrote down the stars they saw and the motion relationships between them, and found you, who has already proved P=NPP=NP, hoping you can tell them who was correct in the end.

Input Format

The first line contains a positive integer TT, the number of test cases. For each test case:

  • The first line contains an integer nn, the number of stars each of Renko and Merry found first.
  • The second line contains an integer mm, the number of motion relationships.
  • The next mm lines each contain two integers ui,viu_i, v_i, meaning that there exists a motion relationship between the uiu_i-th Renko Star and the viv_i-th Merry Star.

Output Format

  • If there exists a unique harmonious motion among these stars, output Renko.
  • If there is no harmonious motion, or the harmonious motion is not unique, output Merry.
1
5
6
1 1
1 3
3 2
2 5
4 3
5 4
Renko

Hint

Sample Explanation

Sample #1

As shown in the figure, there is a unique solution: {11,25,32,43,54}\{1\to 1,2\to 5,3\to 2,4\to 3,5\to 4\}.

Constraints

This problem uses bundled testdata.

$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c|c|}\hline \textbf{Subtask} & \textbf{\textsf{分值}} & \bm{n\le } & \bm{m\le} & \textbf{\textsf{特殊性质}} & \textbf{Subtask \textsf{依赖}}\cr\hline 1 & 10 & 10 & 10 & - & - \cr\hline 2 & 20 & 300 & 4\times 10^4 & - & 1\cr\hline 3 & 20 & 10^5 & 5 \times 10^5 & \mathbf{A} & - \cr\hline 4 & 20 & 10^5 & 2 \times 10^5 & \mathbf{B} & - \cr\hline 5 & 30& 10^6 & 2\times 10^6 & - & 2,3,4 \cr\hline \end{array}$$
  • Special property A\mathbf{A}: It is guaranteed that there exists a motion relationship between the ii-th Renko Star and the ii-th Merry Star.
  • Special property B\mathbf{B}: It is guaranteed that m=2n1m = 2n - 1.

For 100%100\% of the data, it is guaranteed that 1ui,vin1061 \le u_i, v_i \le n \le 10^6, 1m2×1061 \le m \le 2 \times 10^6, 1T51 \leq T \leq 5, and for each test point, m4×106\sum m \leq 4 \times 10^6.

For Subtask 5\rm Subtask\ 5, the time limit is 33 seconds. For the other test points, the time limit is 11 second.

Translated by ChatGPT 5