QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#10982. 最小距离树

Estadísticas

给定一个包含 $N$ 个顶点(编号从 $1$ 到 $N$)和 $M$ 条边的连通无向加权简单图 $G$。第 $i$ 条边连接顶点 $u_i$ 和 $v_i$,权重为 $w_i$。

请判断是否存在一个同样包含 $N$ 个顶点(编号从 $1$ 到 $N$)的加权树 $T$,使得对于任意一对顶点 $u$ 和 $v$,在 $G$ 中的最短路径长度与在 $T$ 中的最短路径长度相等。

输入格式

输入格式如下:

$N$ $M$ $u_1$ $v_1$ $w_1$ $u_2$ $v_2$ $w_2$ $\vdots$ $u_M$ $v_M$ $w_M$

  • 所有输入值均为整数。
  • $2 \le N \le 5 \times 10^5$。
  • $N - 1 \le M \le 5 \times 10^5$。
  • $1 \le u_i, v_i \le N$。
  • $1 \le w_i \le 10^9$。
  • 给定图为简单连通图。

输出格式

如果存在这样的树 $T$,输出: Yes

否则,输出: No

样例

样例输入 1

3 3
1 2 3
2 3 4
3 1 100

样例输出 1

Yes

样例输入 2

3 3
1 2 3
2 3 4
3 1 2

样例输出 2

No

说明

在第一个样例中,一棵包含 3 个顶点的树 $T$(其中顶点 1 与顶点 2 相连,权重为 3;顶点 2 与顶点 3 相连,权重为 4)满足条件。

在第二个样例中,不存在这样的树 $T$。例如,一棵顶点 1 与顶点 2 相连(权重 2),且顶点 1 与顶点 3 相连(权重 2)的树不满足条件,因为在 $G$ 中 1 和 2 之间的最短路径长度为 3,而在该树中为 2,两者不相等。

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.