QOJ.ac

QOJ

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

#8489. 平地之街

Statistics

Flatland 是一个位于平面上的国家。Flatland 共有 $n$ 座城市,由 $n-1$ 条双向道路连接,使得从任意城市出发都能到达其他任何城市。第 $i$ 座城市位于坐标 $(x_i, y_i)$ 处。

最近,Flatland 决定进行道路改革,并为每条道路命名。为了节省资源,决定尽可能使用最少的不同名称。如果几条道路构成一条简单路径,且对于该路径上任意两条连续的道路 $(u, v)$ 和 $(v, w)$,有向道路对 $u \to v$ 和 $v \to w$ 是兼容的,且有向道路对 $w \to v$ 和 $v \to u$ 也是兼容的,那么这些道路可以被赋予相同的名称。

在这种情况下,如果从点 $v$ 出发,在将向量 $\vec{uv}$ 绕点 $v$ 旋转至向量 $\vec{vw}$ 的过程中,没有遇到其他从城市 $v$ 出发的道路,则称有向道路对 $u \to v$ 和 $v \to w$ 是兼容的。

兼容的有向道路对 $u \to v$ 和 $v \to w$、不兼容的有向道路对 $u \to v$ 和 $v \to w$ 以及同向道路

注意,道路必须在两个方向上都兼容,而插图仅展示了一个方向上的兼容性。此外,如果从 $v$ 出发的向量 $\vec{uv}$ 与某条道路同向,则认为该道路是与道路 $(u, v)$ 唯一的兼容道路。

由一条或多条具有相同名称的道路组成的路径称为“高速公路”。请确定将 Flatland 的所有道路划分成不同名称的高速公路所需的最少数量。

输入格式

第一行包含一个整数 $n$ —— Flatland 中的城市数量 ($1 \le n \le 2 \cdot 10^5$)。

接下来的 $n$ 行中,第 $i$ 行包含两个整数 $x_i$ 和 $y_i$ —— 第 $i$ 座城市的坐标 ($|x_i|, |y_i| \le 10^9$)。保证平面上没有两座城市位于同一点。

接下来的 $n-1$ 行描述 Flatland 中的道路 —— 第 $i$ 行包含第 $i$ 条道路连接的城市编号 $u_i$ 和 $v_i$ ($1 \le u_i, v_i \le n$)。保证任意两座城市之间有且仅有一条路径。

同时保证从同一城市出发的任意两条道路不共线(同向)。然而,不保证平面上对应于道路的线段不相交。

输出格式

输出一个整数 —— 在为 Flatland 的所有道路命名后,高速公路的最少数量。

样例

样例输入 1

5
0 0
2 4
3 -1
0 -2
-4 -3
1 2
1 3
1 4
1 5

样例输出 1

2

样例输入 2

5
0 0
2 4
3 -1
0 -2
0 3
1 2
1 3
1 4
1 5

样例输出 2

3

说明

题目描述中包含了两个示例的插图。在第一个示例中,可以将路径 $(2, 1, 4)$ 和 $(3, 1, 5)$ 合并为一条高速公路。在第二个示例中,不可能得到少于三条高速公路,因为道路 $(1, 5)$ 和 $(1, 4)$ 仅彼此兼容,而 $(1, 2)$ 和 $(1, 3)$ 不兼容。

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.