Under construction

Still being built. Things may change

Gift Exchange Party

Time limit2sMemory limit512 MB

Summary
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

nn is the number of students and mm is the number of friendship relations (2≤n≤1002 \le n \le 100, 1≤m≤n(n−1)/21 \le m \le n(n-1)/2). Students are denoted by integers between 1 and nn, inclusive. The following mm lines describe the friendship relations: for each ii, student uiu_i and student viv_i are close friends, and ui<viu_i < v_i. 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 ll and hh separated by a single space. Here ll is the smallest and hh is the largest number of gifts received by a student.

Examples7

  1. Example 1

    Input
    3 3
    1 2
    2 3
    1 3
    4 3
    1 2
    1 3
    1 4
    4 6
    1 2
    1 3
    1 4
    2 3
    3 4
    2 4
    0 0
    
    Expected output
    1 1
    0 1
    1 2
    
  2. Example 2

    Input
    2 1
    1 2
    0 0
    
    Expected output
    0 1
    
  3. Example 3

    Input
    4 3
    1 2
    2 3
    3 4
    5 4
    1 2
    1 3
    1 4
    1 5
    0 0
    
    Expected output
    0 1
    0 1
    
  4. Example 4

    Input
    4 4
    1 2
    2 3
    3 4
    1 4
    5 5
    1 2
    2 3
    3 4
    4 5
    1 5
    5 10
    1 2
    1 3
    1 4
    1 5
    2 3
    2 4
    2 5
    3 4
    3 5
    4 5
    0 0
    
    Expected output
    1 1
    1 1
    2 2
    
  5. Example 5

    Input
    5 6
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4
    0 0
    
    Expected output
    0 2
    
  6. Example 6

    Input
    6 6
    1 2
    2 3
    1 3
    4 5
    5 6
    4 6
    4 4
    1 2
    1 3
    2 3
    3 4
    0 0
    
    Expected output
    1 1
    1 1
    
  7. Example 7

    Input
    3 1
    1 2
    3 2
    1 2
    1 3
    3 3
    1 2
    1 3
    2 3
    0 0
    
    Expected output
    0 1
    0 1
    1 1