Dicing
Time limit3sMemory limit128 MB
Given an undirected multigraph of m games among n players, orient every edge so that the maximum number of edges pointing into any vertex is minimized.
- Level
Medium7 of 10
- Topics
- Graph, Binary search, Greedy, Implementation
- Solved
- No attempts yet
Statement
Dicing is a two-player game whose outcome is entirely a matter of luck. Lately it has been gaining popularity all over Byteotia, and the capital even has a dedicated club for dicing enthusiasts. The club's patrons chat with one another and, every now and then, play their favourite game against a randomly chosen opponent. Whoever wins the most games in a single day earns the title of lucky chap. On a quiet night only a few games are played, and then even a single win can be enough to become the lucky chap.
One day the perennially unlucky Byteasar won this glorious title. He was so stunned that he completely forgot how many games he had won. He remembers exactly who played whom and how many games took place that night, but not the result of any game. Byteasar wonders what the smallest number of wins is that could have earned him the title.
In other words: if the winner of each game may be chosen freely, find the smallest integer such that it is possible for no player to win more than games.
Input
The first line contains two integers and separated by a single space (, ), where is the number of players and is the number of games. Players are numbered from to . Each of the next lines contains the numbers of the two players who took part in one game, separated by a single space. The same pair may appear multiple times.
Output
Output a single line containing the smallest integer such that the winner of every game can be chosen so that no player wins more than games.