QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#12909. 同构

Statistics

图同构是计算机科学中的一个重要问题。目前尚不清楚该问题是否存在多项式时间算法,也不清楚它是否是 NP-完全问题。

两个无向图 $G$ 和 $H$ 被称为同构的,如果它们具有相同数量的顶点,并且存在一个双射 $\phi : V_G \to V_H$,使得 $G$ 中存在边 $uv$ 当且仅当 $H$ 中存在边 $\phi(u)\phi(v)$。图中有一些在同构下不变的特征。其中一个参数是图的度分布(degree profile)。

顶点 $u$ 的度 $\text{deg}(u)$ 是与 $u$ 相连的其他顶点的数量。考虑一个具有 $n$ 个顶点的连通无向图 $G$。对于每个顶点 $u$,找出距离 $u$ 为 $0, 1, \dots, n-1$ 的顶点集合 $V_{u,0}, V_{u,1}, \dots, V_{u,n-1}$(其中一些集合可能为空)。对于每个这样的集合,找出其中顶点度的多重集 $D_{u,i}$。这些多重集的列表 $D_u = [D_{u,0}, D_{u,1}, \dots, D_{u,n-1}]$ 即为顶点 $u$ 的度分布。图中所有顶点的度分布构成的多重集即为该图的度分布。

例如,下图所示的图具有度分布 $[\{1\}, \{2\}, \{1\}], [\{2\}, \{1, 1\}, \emptyset], [\{1\}, \{2\}, \{1\}]$。

显然,度分布在同构下是不变的。然而,可能存在具有相同度分布但不同构的图。下图展示了两个这样的图。两个图中度为 2 的顶点具有度分布 $[\{2\}, \{3, 3\}, \{3, 3\}, \{2\}, \emptyset, \emptyset]$,度为 3 的顶点具有度分布 $[\{3\}, \{2, 3, 3\}, \{2, 3\}, \emptyset, \emptyset, \emptyset]$,但这些图显然是不同构的。

注意,当不同的度分布证明图不同构时,相同的度分布并不能提供一种简单的方法来寻找同构(即使同构存在),因为建立具有相同度分布的顶点之间的对应关系可能很困难。然而,有一类图,其度分布可以很容易地用于检查同构。这类图的所有顶点都具有不同的度分布。我们称这样的图为度可区分(degree distinguishable)图。

然而,即使是度可区分图,也可能具有相同的度分布但不同构。给定 $n$,请找出两个具有 $n$ 个顶点的非同构连通度可区分图,且它们具有相同的度分布。

输入格式

输入包含一个整数 $n$ ($3 \le n \le 100$)。

输出格式

如果不存在两个具有 $n$ 个顶点的非同构度可区分图且具有相同的度分布,则在输出文件的第一行打印 “NO”。否则,打印 “YES”,随后输出两个图的描述。

每个描述必须以 $m$(边的数量)开头,随后是 $m$ 对整数:由边连接的顶点对。任意一对顶点之间最多只能有一条边,且不允许存在自环。

每个图的顶点必须编号为 $1$ 到 $n$,使得两个图中编号为 $i$ 的顶点具有相同的度分布。同一图中任意两个顶点不能具有相同的度分布。

说明

第二个样例给出了两个具有相同度分布但不是度可区分的非同构图。它们仅用于说明输出格式,但对于 $n=6$ 这样的输出将不被接受。

样例

输入 1

3

输出 1

NO

输入 2

6
YES
8
1 2
1 6
2 3
2 5
3 4
3 6
4 5
5 6
8
1 2
1 6
2 3
2 6
3 4
3 5
4 5
5 6

说明 2

Note that this is incorrect output

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.