codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1833E.md (1994B)


      1 Source: https://codeforces.com/problemset/problem/1833/E
      2 
      3 E. Round Dance
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 $n$ people came to the festival and decided to dance a few round dances. There are at least $2$ people in the round dance and each person has exactly two neighbors. If there are $2$ people in the round dance then they have the same neighbor on each side.
     22 
     23 You decided to find out exactly how many dances there were. But each participant of the holiday remembered exactly one neighbor. Your task is to determine what the minimum and maximum number of round dances could be.
     24 
     25 For example, if there were $6$ people at the holiday, and the numbers of the neighbors they remembered are equal $[2, 1, 4, 3, 6, 5]$, then the minimum number of round dances is$1$:
     26 
     27 * $1 - 2 - 3 - 4 - 5 - 6 - 1$
     28 
     29 and the maximum is $3$:
     30 
     31 * $1 - 2 - 1$
     32 * $3 - 4 - 3$
     33 * $5 - 6 - 5$
     34 
     35 Input
     36 
     37 The first line contains a positive number $t$ ($1 \le t \le 10^4$) — the number of test cases. The following is a description of the test cases.
     38 
     39 The first line of the description of each test case contains a positive number $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of people at the holiday.
     40 
     41 The second line of the description of each test case contains $n$ integers $a_i$ ($1 \le a_i \le n, a_i \neq i$) — the number of the neighbor that the $i$th person remembered.
     42 
     43 It is guaranteed that the test cases are correct and corresponds to at least one division of people into round dances.
     44 
     45 It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$.
     46 
     47 Output
     48 
     49 For each test case, output two integers — the minimum and maximum number of round dances that could be.
     50 
     51 Example
     52 
     53 Input
     54 
     55 ```
     56 10
     57 
     58 6
     59 
     60 2 1 4 3 6 5
     61 
     62 6
     63 
     64 2 3 1 5 6 4
     65 
     66 9
     67 
     68 2 3 2 5 6 5 8 9 8
     69 
     70 2
     71 
     72 2 1
     73 
     74 4
     75 
     76 4 3 2 1
     77 
     78 5
     79 
     80 2 3 4 5 1
     81 
     82 6
     83 
     84 5 3 4 1 1 2
     85 
     86 5
     87 
     88 3 5 4 1 2
     89 
     90 6
     91 
     92 6 3 2 5 4 3
     93 
     94 6
     95 
     96 5 1 4 3 4 2
     97 ```
     98 
     99 Output
    100 
    101 ```
    102 1 3
    103 2 2
    104 1 3
    105 1 1
    106 1 2
    107 1 1
    108 1 1
    109 2 2
    110 1 2
    111 1 1
    112 ```