Almost Union-Find

题目描述

[problemUrl]: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=229&page=show_problem&problem=3138 [PDF](https://uva.onlinejudge.org/external/119/p11987.pdf) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA11987/26c36f66c6f7a4f753621f5225d4d163683ff773.png)

输入输出格式

输入格式


![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA11987/a62dd792a69a4914dd19a578a5f43c1857d54517.png)

输出格式


![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA11987/71c634954dff55daeaad092e9a80a67b382b6644.png)

输入输出样例

输入样例 #1

5 7
1 1 2
2 3 4
1 3 5
3 4
2 4 1
3 4
3 3

输出样例 #1

3 12
3 7
2 8