CF755F.PolandBall and Gifts

省选/NOI-

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall. Each Ball has someone for whom he should bring a present according to some permutation p, p__i ≠ i for all i.

Unfortunately, Balls are quite clumsy. We know earlier that exactly k of them will forget to bring their gift. A Ball number i will get his present if the following two constraints will hold:

  1. Ball number i will bring the present he should give.
  2. Ball x such that p__x = i will bring his present.

What is minimum and maximum possible number of kids who will not get their present if exactly k Balls will forget theirs?

现在是圣诞节啦!PolandBall 和他的朋友们将互相赠送礼物。一共有 nn 个 Ball。每个 Ball 根据某个排列 pp 为某个人准备礼物,且对所有 ii 均满足 pi≠ip_i \neq i。

不幸的是,这些 Ball 非常笨拙。我们已知恰好有 kk 个 Ball 会忘记带自己的礼物。编号为 ii 的 Ball 能收到他的礼物,当且仅当以下两个条件同时成立:

  1. 编号为 ii 的 Ball 带来了他本应送出的礼物;
  2. 编号为 xx 的 Ball(满足 px=ip_x = i)带来了他本应送出的礼物。

如果恰好有 kk 个 Ball 忘记带礼物,那么未能收到礼物的 Ball 的最小可能数量和最大可能数量分别是多少?

输入格式

The first line of input contains two integers n and k (2 ≤ n ≤ 106, 0 ≤ k ≤ n), representing the number of Balls and the number of Balls who will forget to bring their presents.

The second line contains the permutation p of integers from 1 to n, where p__i is the index of Ball who should get a gift from the i-th Ball. For all i, p__i ≠ i holds.

输入的第一行包含两个整数 nn 和 kk(2 ≤ n ≤ 1062 \leq n \leq 10^6,0 ≤ k ≤ n0 \leq k \leq n),分别表示小球的数量以及忘记带礼物的小球数量。

第二行包含一个 11 到 nn 的排列 pp,其中 pip_i 表示第 ii 个小球本应将礼物送给的小球的编号。对所有 ii,均有 pi≠ip_i \neq i。

输出格式

You should output two values — minimum and maximum possible number of Balls who will not get their presents, in that order.

你应该输出两个值——无法收到礼物的 Ball 的最小可能数量和最大可能数量,按此顺序输出。

输入输出样例

  • 输入#1

    5 2
    3 4 1 5 2

    输出#1

    2 4
  • 输入#2

    10 1
    2 3 4 5 6 7 8 9 10 1

    输出#2

    2 2

说明/提示

In the first sample, if the third and the first balls will forget to bring their presents, they will be th only balls not getting a present. Thus the minimum answer is 2. However, if the first ans the second balls will forget to bring their presents, then only the fifth ball will get a present. So, the maximum answer is 4.

在第一个样例中,如果第三个球和第一个球忘记带礼物,那么它们将是唯二没有收到礼物的球。因此,最小答案为 2。然而,如果第一个球和第二个球忘记带礼物,则只有第五个球会收到礼物。因此,最大答案为 4。

输入解题思路,AI测评打分。不知道怎么写?

首页