Data Center Maintenance
InterviewTime limit1sMemory limit1024 MB
Given data center maintenance hours and client pairs, find the fewest data centers to shift one hour later so every client keeps one copy reachable.
- Level
Medium6 of 10
- Topics
- Graph, DFS, Implementation
- Solved
- No attempts yet
Statement
BigData Inc. operates data centers, numbered from 1 to , spread across the world. They store client data. The company promises that clients can still reach their data when any one data center has an outage. This guarantee comes from two-way replication: every piece of data is stored as two identical copies in two different data centers.
The company has clients. For client , let and be the indices of the two different data centers that store that client's data.
Each data center installs a software update once a day. The day is exactly hours long, and each data center has a maintenance hour (), during which it is unavailable. For every client, must hold. Otherwise, both copies could be down at the same time and the client's data becomes inaccessible.
Timezone changes sometimes move a data center's maintenance time by one hour. To study this, the company runs an experiment. It picks a non-empty subset of data centers and moves each of their maintenance hours one hour later. If , the new hour is 0. Otherwise it is . The experiment must keep the guarantee intact: at every hour of the day, every client still has at least one reachable copy.
Changing a maintenance time is expensive, so find the smallest number of data centers that must be included in the experiment.
Input
The first line contains three integers , , and (, , ). The second line contains integers (). Each of the next lines contains two integers and (, ). The input guarantees that the given schedule lets every client reach at least one copy at every moment of the day.
Output
On the first line, print the minimum number of data centers () that must be included in the experiment. On the second line, print distinct indices () of the data centers whose maintenance hour moves one hour later. The order does not matter. If several answers exist, any of them is accepted. At least one valid choice is guaranteed to exist.
Hint
In the first sample, the printed answer is the only single data center that works. Data center 3 has maintenance at hour 0, and no two data centers that share a client have maintenance at the same hour. If you shift data center 1 instead, the data of clients 1 and 3 becomes unreachable at hour 0.