QOJ.ac

QOJ

시간 제한: 2.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓

#14504. 挑戰圖同構

통계

在研究圖同構問題時,Pog 遇到了一些困難。眾所周知,圖同構是計算複雜性理論中的一個著名難題,其確切複雜性至今仍未被完全確定。於是,Pog 決定對圖同構問題的定義進行修改。

首先,在一張帶權無向圖 $G$ 中,定義路徑 $u \to x_1 \to \dots \to x_k \to v$ 的權值為該路徑上所有邊權的最大值。

接下來,定義圖 $G$ 上兩個不同的點 $u, v$ ($u \neq v$) 之間的距離 $\text{dis}_{G,u,v}$ 為所有 $u$ 到 $v$ 的路徑的權值的最小值。若 $u$ 和 $v$ 不連通(即不存在 $u$ 到 $v$ 的路徑),那麼定義 $\text{dis}_{G,u,v} = +\infty$。

定義兩個具有 $n$ 個頂點,編號為 $1, 2, \dots, n$ 的圖 $G_1, G_2$ 同構,當且僅當對於所有的 $u, v$ ($1 \le u, v \le n, u \neq v$),有 $\text{dis}_{G_1,u,v} = \text{dis}_{G_2,u,v}$。請注意,這個定義與通常意義上的同構不同,不允許重新進行編號。

現在,請你幫助 Pog 判定在該新的定義下,給定的兩張圖是否同構。

輸入格式

本題有多組數據,第一行一個整數 $T$ ($1 \le T \le 10^4$),表示數據組數。

對於每組數據: 第一行三個整數 $n, m_1, m_2$ ($1 \le n \le 10^5, 1 \le m_1, m_2 \le 2 \times 10^5$) 表示圖的點數和 $G_1, G_2$ 的邊數。 接下來 $m_1$ 行,每行三個整數 $u, v, w$ ($1 \le u, v \le n, 1 \le w \le 10^9$) 表示 $G_1$ 上的一條邊。 接下來 $m_2$ 行,每行三個整數 $u, v, w$ ($1 \le u, v \le n, 1 \le w \le 10^9$) 表示 $G_2$ 上的一條邊。

保證 $T$ 組數據中 $n$ 的和不超過 $10^5$,$m_1$ 的和與 $m_2$ 的和均不超過 $2 \times 10^5$。注意,圖中可能存在重邊、自環,也可能不連通。

輸出格式

對於每組數據: 輸出一行一個字串,若同構,輸出 YES,否則輸出 NO(不區分大小寫)。

範例

輸入 1

3
2 1 1
1 2 1
1 2 2
2 1 1
1 2 1
1 2 1
3 3 3
1 2 1
1 3 1
2 3 2
1 2 1
1 3 2
2 3 1

輸出 1

NO
YES
YES

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.