QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 512 MB 總分: 100 可 Hack ✓

#15973. 树镜像

统计

设 $T$ 是一棵有根树(一个连通的无向无环图),并设 $S$ 是 $T$ 的一个完全复制。 通过取 $T$ 和 $S$ 的并集,并合并它们对应的叶子节点(但绝不合并根节点)来构建一个新图。我们称这样的图为树镜对称图(tree-mirrored graph)。

编写一个程序,判断一个给定的任意无向连通图是否为树镜对称图。

图 1:一个树镜对称图的例子。该图对应第三个样例测试数据。

输入格式

输入的第一行包含两个整数 $N$ 和 $M$,分别表示图 $G$ 的顶点数和边数。

图 $G$ 中的顶点编号为 $1$ 到 $N$。接下来的 $M$ 行描述了图中的边。每行包含两个整数 $x$ 和 $y$($x \neq y$ 且 $1 \le x, y \le N$),描述一条边。任意两个顶点之间最多只有一条边。

输出格式

输出的第一行也是唯一的一行应当包含字符串 YES(如果图 $G$ 是一个树镜对称图)或 NO(如果不是)。

数据范围

  • $3 \le N, M \le 100\,000$
  • 在价值 $60$ 分的测试数据中,$3 \le N, M \le 3\,500$。
  • 在价值 $30$ 分的测试数据中,$3 \le N, M \le 300$。

样例

输入样例 1

7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1

输出样例 1

NO

输入样例 2

6 6
1 2
2 3
2 4
3 5
4 5
5 6

输出样例 2

YES

输入样例 3

22 28
13 8
8 1
1 22
1 12
1 14
13 18
13 4
4 20
20 7
13 15
15 3
15 9
9 16
9 19
22 5
12 5
14 5
5 11
11 6
18 6
7 10
10 17
17 6
3 21
21 6
16 2
19 2
2 21

输出样例 3

YES

说明

最后一个样例输入对应插图中的图。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.