CF81E Pairs

题目描述

有 $n$ 个人,每个人都有自己最好的朋友,**但不保证 a 的最好朋友是 b 时,b 的最好朋友是 a**。 现在要把他们和自己最好的朋友两两分组,因为不一定全部人都能被分在一起,所以求在组数最多的情况下,男女组最多。

输入格式

第一行输入 $n$。 接下来 $n$ 行,每行两个整数,第 $i$ 行第一个数为编号为 $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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF81E/d4459c987cdcafcc124667d05e81918009e49fed.png)