Ուղարկել | Բոլոր լուծումները | Լավագույն լուծումները | Վերադառնալ ցուցակին |
ACM_0195 - OUTING |
Organising a group trip for the elderly can be a daunting task... Not least because of the fussy partici- pants, each of whom will only make the trip on condi- tion that some other participant also comes.
After some effort, you have taken from each of your participants a number, indicating that this participant will refuse to join the excursion unless the participant with that number also joins– the less choosy simply give their own number. This would be easy enough to resolve (just send all of them) but the bus you are going to use during the trip has only a fixed number of places.
Task
Given the preferences of all participants, find the max- imum number of participants that can join.
Input
The first line of input contains two integers n and k (1 ≤ k ≤ n ≤ 1 000), where n denotes the total number of participants and k denotes the number of places on the bus.
The second line contains n integers xi for i = 1, 2, . . . , n, where 1 ≤ xi ≤ n. The meaning, of xi is that the i-th participant will refuse to join the excursion unless the xi-th participant also joins.
Output
Output one integer: the maximum number of participants that can join the excursion, so that all the participants’ preferences are obeyed and the capacity of the bus is not exceeded.
Examples
№ |
stdin |
stdout |
1 |
4 4 1 2 3 4 |
4 |
2 |
12 3 2 3 4 5 6 7 4 7 8 8 12 12 |
2 |
3 |
5 4 2 3 1 5 4 |
3 |
Ավելացրեց. | Հրանտ Հովհաննիսյան |
Ամսաթիվ. | 2014-10-08 |
Ժամանակի սահմանափակումը. | 1s |
Ծրագրի տեքստի սահմանափակումը. | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Լեզուներ. | Բոլորը բացի ASM32 ASM64 GAWK CLPS CLOJURE D ERL FSHARP FORTRAN GOSU HASK ICON ICK NEM NIM OBJC-CLANG PICO PIKE PYPY PYPY3 PY_NBC RUST SCM guile CHICKEN SED TCL WHITESPACE |
Աղբյուրը. | Nordic (NCPC) 2014.G |