Gift Exchange Party
Time limit2sMemory limit512 MB
Orient every edge of an undirected graph so that the max out-degree minus min out-degree is minimized, then among such orientations maximize the min out-degree. Output those two values.
- Level
Hard8 of 10
- Topics
- Graph, Greedy, Binary search, Math
- Solved
- No attempts yet
Problem
A school in TKB City holds a gift exchange party.
Every pair of students who are close friends passes one gift at this party. One of the two gives a gift to the other, and nothing goes back the other way. Which student of each pair receives the gift is fixed before the party. No other gift passes between students.
If every pair picked its direction at random, one student could end up with a heap of gifts while another gets one or none at all.
Choose the gift direction for every friend pair so that the difference between the largest and the smallest number of gifts a student receives is as small as possible. Report the smallest and the largest number of gifts received once that difference is minimized. When several choices reach that minimum difference, take the one whose smallest number of received gifts is largest.
Input
The input consists of at most 10 datasets. Each dataset has the following format.
n m
u1 v1
...
um vm
is the number of students and is the number of friendship relations (, ). Students are denoted by integers between 1 and , inclusive. The following lines describe the friendship relations: for each , student and student are close friends, and . The same friendship relation never appears more than once. A student may have no friends at all.
A line containing two zeros ends the input.
Output
For each dataset, print one line containing two integers and separated by a single space. Here is the smallest and is the largest number of gifts received by a student.