102931: [Atcoder]ABC293 B - Call the ID Number

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:2 Solved:0

Description

Score : $200$ points

Problem Statement

There are $N$ people whose IDs are $1$, $2$, $\ldots$, and $N$.

Each of person $1$, person $2$, $\ldots$, and person $N$ performs the following action once in this order:

  • If person $i$'s ID has not been called out yet, call out person $A_i$'s ID.

Enumerate the IDs of all the people whose IDs are never called out until the end in ascending order.

Constraints

  • $2 \leq N \leq 2 \times 10^5$
  • $1 \leq A_i \leq N$
  • $A_i \neq i$
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\ldots$ $A_N$

Output

Enumerate the IDs of all the people whose IDs are not called out until the end in ascending order in the following format:

$K$
$X_1$ $X_2$ $\ldots$ $X_K$

In other words, the first line should contain the number of people, $K$, whose IDs are never called out until the end; the second line should contain the sequence $(X_1, X_2, \ldots, X_K)$ of IDs of such people in ascending order, with spaces in between.


Sample Input 1

5
3 1 4 5 4

Sample Output 1

2
2 4

The five people's actions are as follows.

  • Person $1$'s ID has not been called out yet, so person $1$ calls out person $3$'s ID.
  • Person $2$'s ID has not been called out yet, so person $2$ calls out person $1$'s ID.
  • Person $3$'s ID has already been called out by person $1$, so nothing happens.
  • Person $4$'s ID has not been called out yet, so person $4$ calls out person $5$'s ID.
  • Person $5$'s ID has already been called out by person $4$, so nothing happens.

Therefore, person $2$ and $4$'s IDs are not called out until the end.


Sample Input 2

20
9 7 19 7 10 4 13 9 4 8 10 15 16 3 18 19 12 13 2 12

Sample Output 2

10
1 2 5 6 8 11 14 17 18 20

Input

题意翻译

给定一个长度为 $N$ 的序列 $a$ 依次对 $i=1,2,\cdots ,N$ 执行以下操作: 如果当前纸上还未写下 $i$,就在纸上写下 $a_i$,否则什么也不做。 问:$1,2,\cdots,N$ 中,有多少个数未被写下,分别是几。

Output

得分:200分

问题描述

有$N$个人,他们的ID分别是1, 2, ..., 和$N$。

每个人按顺序执行以下操作一次:

  • 如果第$i$个人的ID还没有被叫到,就叫出第$A_i$个人的ID。

按升序列出直到最后都没有被叫到ID的所有人的ID。

约束

  • $2 \leq N \leq 2 \times 10^5$
  • $1 \leq A_i \leq N$
  • $A_i \neq i$
  • 输入中的所有值都是整数。

输入

输入以标准输入的以下格式给出:

$N$
$A_1$ $A_2$ $\ldots$ $A_N$

输出

按以下格式按升序列出直到最后都没有被叫到ID的所有人的ID:

$K$
$X_1$ $X_2$ $\ldots$ $X_K$

换句话说,第一行应该包含没有被叫到ID的人数$K$; 第二行应该包含这些人的ID序列$(X_1, X_2, \ldots, X_K)$,以空格分隔。


样例输入1

5
3 1 4 5 4

样例输出1

2
2 4

五个人的操作如下。

  • 第$1$个人的ID还没有被叫到,所以第$1$个人叫出第$3$个人的ID。
  • 第$2$个人的ID还没有被叫到,所以第$2$个人叫出第$1$个人的ID。
  • 第$3$个人的ID已经被第$1$个人叫出,所以什么也不发生。
  • 第$4$个人的ID还没有被叫到,所以第$4$个人叫出第$5$个人的ID。
  • 第$5$个人的ID已经被第$4$个人叫出,所以什么也不发生。

因此,直到最后都没有被叫到ID的是第$2$个人和第$4$个人。


样例输入2

20
9 7 19 7 10 4 13 9 4 8 10 15 16 3 18 19 12 13 2 12

样例输出2

10
1 2 5 6 8 11 14 17 18 20

HINT

n个人,只要没被淘汰,就能依次投票,一票否决其他人,最终剩下哪些人?

加入题单

算法标签: