CF81E Pairs
题目描述
有 $n$ 个人,每个人都有自己最好的朋友,**但不保证 a 的最好朋友是 b 时,b 的最好朋友是 a**。
现在要把他们和自己最好的朋友两两分组,因为不一定全部人都能被分在一起,所以求在组数最多的情况下,男女组最多。
输入格式
第一行输入 $n$($2 \le n \le 10^5$)。
接下来 $n$ 行,每行两个整数 $f_i,s_i$($1 \le f_i \le n,f_i \neq i,1 \le s_i \le 2$),$f_i$ 为第 $i$ 个人的最好的朋友,$s_i$ 为他的性别。男用 $1$ 表示,女用 $2$ 表示。
输出格式
输出两个数,为最多组数和最多男女匹配组数。
然后将所有匹配成功的两个人的编号输出出来。
说明/提示
The picture corresponds to the first sample. On the picture rhomb stand for boys, squares stand for girls, arrows lead from a pupil to his/her best friend. Bold non-dashed arrows stand for pairs in the answer.
