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$ 上の異なる2点 $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$ と番号付けられた2つのグラフ $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}$ が成り立つことと定義します。この定義は通常の意味での同型とは異なり、頂点の番号の付け替えは許可されないことに注意してください。

この新しい定義の下で、与えられた2つのグラフが同型かどうかを判定してください。

入力

入力は複数のテストケースから構成されます。最初の行にテストケースの数 $T$ ($1 \le T \le 10^4$) が与えられます。

各テストケースは以下の形式で与えられます。

最初の行に3つの整数 $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$ 行には、それぞれ3つの整数 $u, v, w$ ($1 \le u, v \le n, 1 \le w \le 10^9$) が与えられ、$G_1$ 上の辺を表します。

続く $m_2$ 行には、それぞれ3つの整数 $u, v, w$ ($1 \le u, v \le n, 1 \le w \le 10^9$) が与えられ、$G_2$ 上の辺を表します。

すべてのテストケースにおける $n$ の総和は $10^5$ を超えず、$m_1$ の総和および $m_2$ の総和はそれぞれ $2 \times 10^5$ を超えません。グラフには多重辺や自己ループが含まれる可能性があり、連結でない場合もあります。

出力

各テストケースについて、同型であれば YES を、そうでなければ NO を1行で出力してください(大文字・小文字は区別しません)。

入出力例

入力 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.