CF1559D2 Mocha and Diana (Hard Version)

题目描述

给你两棵森林,节点数均为 $n$。 允许你进行加边操作,但是有两个要求: - 如果在第一个森林加一条 $(u,v)$ 的边,第二个森林也要进行同样的操作。反之同理。 - 加边后两个森林依旧是森林。(一棵树也是森林) 求最多能加几条边,并输出加边方案。

输入格式

输出格式

说明/提示

In the first example, we cannot add any edge. In the second example, the initial forests are as follows. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1559D2/3b441afdf7fd87635afa8212e7dfecc8d4b6f286.png) We can add an edge $ (2, 4) $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1559D2/98bbd9b512604aa18a1dece7b72cf916b7a8fd6d.png)