#P16123. [USTCPC 2026] Kruskal Loves Strongly Connected Graph
[USTCPC 2026] Kruskal Loves Strongly Connected Graph
Background
Please note that this problem has non-standard time and memory limits.
Due to differences in judge machine performance, the time limit has been adjusted to 0.5 s.
Kruskal-chan likes strongly connected graphs, and she is dedicated to exploring their strong connectivity on various graphs.
Problem Description
You are given a sequence of length .
Define . In particular, if there is no such that , then .
There is a directed edge between and if and only if , , and .
Kruskal-chan wants to add some directed edges so that the new graph after adding them is strongly connected.
Please tell her the minimum number of edges that need to be added, and construct a solution.
Note: A graph is strongly connected if and only if for any , both a path from to and a path from to exist.
Input Format
The first line contains a positive integer , denoting the length of the sequence.
The second line contains integers. The -th positive integer denotes the -th element of the sequence.
Output Format
The first line outputs an integer , denoting the minimum number of edges to add.
In the next lines, each line outputs two positive integers separated by a space, denoting an added directed edge .
You need to ensure that and .
6
2 1 3 5 4 1
3
6 1
4 2
5 6
Hint
Translated by ChatGPT 5