#P10163. [DTCPC 2024] 平方树
[DTCPC 2024] 平方树
Problem Description
You are given a forest, and each edge has a direction.
You can perform two types of operations:
-
Add a new node.
-
Add a directed edge between two nodes.
You need to make it so that in the end, if you treat all directed edges as undirected edges, the graph becomes a tree, and the out-degree of every node is a perfect square.
Provide a plan that uses the minimum number of added nodes.
Input Format
The first line contains two integers (), representing the number of nodes and edges in the forest.
The next lines each contain two integers (), indicating a directed edge from to .
It is guaranteed that if you treat each edge as an undirected edge, the graph is a forest.
Output Format
The first line contains two integers , representing the number of nodes you add and the number of edges you add.
The next lines each contain two integers , indicating that you add a directed edge from to . You must ensure that .
3 2
1 2
1 3
2 2
1 4
1 5
Hint
Translated by ChatGPT 5