#P10654. [ROI 2017] 水星上的服务器 (Day 2)
[ROI 2017] 水星上的服务器 (Day 2)
Problem Description
There are servers on Mercury and data cables. The -th cable connects server and server in both directions.
Suppose server receives a message sent from Earth. You need to transmit the message to all other servers as quickly as possible.
After a server receives the message from Earth, it can immediately store a copy in its database, and then keep it in its buffer for seconds before deleting it.
Due to some external factors, the -th data cable can transmit information only during the time interval . When a cable is active, if at least one of the two servers at its ends still has the message in its buffer, then the other one can obtain the message as well. (After a server receives the message, it will forward the message at the earliest possible time.)
You may choose any time to send the message from Earth to server . In the end, all servers must receive this message. Find the earliest time at which you can send the message. If no feasible solution exists, output .
Input Format
The first line contains an integer .
The second line contains integers .
In the next lines, each line contains two integers .
Output Format
Output lines, each containing one integer. The number on line is the answer when . If it is impossible, output .
1
10
0
2
3 5
6 8
3
1
3
1 2 4
7 10
3 5
-1
5
5
4
1 0 3 2
4 6
5 5
7 10
5
5
4
-1
Hint
Sample Explanation
For sample group #3:
If server receives the patch first, then server cannot get the patch, because channel closes before channel opens. If server receives the patch at second , then server can receive the patch immediately. After that, when channel opens at second , server will receive the patch. If server receives the patch at second , then server can receive the patch immediately. After that, when channel opens at second , server will receive the patch.
For sample group #4:
If server receives the patch first, since server never caches it and channel opens only at second , in order for server to get the patch, you can only choose to send the patch to server at second . If server receives the patch first, you may choose second . Server will cache it until second , so both server and server can get the patch.
Constraints
Note: This problem provides only part of the testdata. For the full testdata, please go to LOJ P2771 for judging.
For all data, .
| Subtask ID | Score | Special Property | |||
|---|---|---|---|---|---|
| None | |||||
| / | |||||
| / | |||||
| None | |||||
| / | |||||
| / | |||||
| None | |||||
Translated by ChatGPT 5