QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 32 MB 總分: 100

#11859. 存钱罐

统计

Byteazar 龙有 $N$ 个存钱罐。每个存钱罐既可以用对应的钥匙打开,也可以砸碎。Byteazar 把钥匙放在了一些存钱罐里——他记得哪把钥匙放在了哪个存钱罐里。Byteazar 打算买一辆车,需要打开所有的存钱罐。然而,他想尽可能少地砸碎存钱罐。请帮助 Byteazar 确定最少需要砸碎多少个存钱罐。

编写一个程序:

  • 从标准输入读取存钱罐的数量以及钥匙的分布情况,
  • 计算为了打开所有存钱罐所需砸碎的最少存钱罐数量,
  • 将结果输出到标准输出。

输入格式

标准输入的第一行包含一个整数 $N$ ($1 \le N \le 1\,000\,000$),即龙拥有的存钱罐数量。存钱罐(以及对应的钥匙)编号从 $1$ 到 $N$。接下来的 $N$ 行中,第 $(i+1)$ 行包含一个整数,表示第 $i$ 把钥匙所在的存钱罐编号。

输出格式

标准输出的第一行应包含一个整数,即为了打开所有存钱罐所需砸碎的最少存钱罐数量。

样例

输入 1

4
2
1
2
4

输出 1

2

说明

在上述示例中,必须砸碎 1 号和 4 号存钱罐。

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.