#P14500. [NCPC 2025] Follower Forensics
[NCPC 2025] Follower Forensics
题目描述
Your social media company ConnectHub prides itself on how easily information spreads through its network.
:::align{center}
:::
Accounts can share posts directly with their followers using the share button, or with the accounts they follow by posting in the comments. ConnectHub is famous for the virality of its users: a post from any account was able to reach every other account, possibly through a chain of shares and comments.
But disaster struck: a database mishap wiped out all records of who follows whom. One piece of data may have survived, though — for each account, you have the number of its followers and the number of accounts it follows. Maybe even those numbers have been corrupted, but it's all you have.
Your task is to rebuild the missing database so that these counts are correct, and ConnectHub once again has full virality.
输入格式
The input consists of:
- One line with an integer , the number of accounts, where .
- One line with integers satisfying for each , where is the number of accounts followed by the th account.
- One line with integers satisfying for each , where is the number of accounts following the th account.
Additionally, it is guaranteed that
$$\sum_{i=1}^n a_i + \sum_{i=1}^n b_i \leq 2\,000\,000.$$Note that the input is not guaranteed to allow for any reconstruction, fully viral or not. For those familiar with that terminology, full virality is equivalent to weak connectivity.
输出格式
If a reconstruction is possible, output a network
- One line with two integers: the number of accounts, and the number of connections. This is the same as in the input.
- Then lines, each consisting of two integers and , specifying that account follows account .
Otherwise output .
Note that it is not allowed for an account to follow the same account twice, nor to follow itself.
5
2 1 2 1 3
0 2 2 3 2
5 9
2 4
4 5
3 5
3 2
5 2
1 3
1 4
5 3
5 4
3
2 2 1
1 1 2
impossible
京公网安备 11011102002149号