#P3425. [POI 2005] KOS-Dicing

    ID: 2480 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2005POI网络流Special Judge生成树最小割

[POI 2005] KOS-Dicing

Description

Dicing is a two-player game and its outcome is fully random. Lately its popularity increases all over Byteotia. There is even a special club for dicing amateurs in the capital city of Byteotia. The club patrons take their time talking to each other and playing their favourite game with a randomly chosen opponent every once in a while. Everyone who wins the most games one day gains the title of the lucky chap. Sometimes it happens that the night at the club is a quiet one and only few games are played. It is a time when even one win can make you a lucky chap.

Once upon a time a most unlucky fellow, Byteasar, won the glorious title. He was so deeply shocked that he completely forgot how many games he had won. Now he is wondering how good his luck was and whether fortune finally smiled upon him - perhaps his luck changed for good? He knows exactly how many games and between whom were played that lucky night. However, he does not know the results. Byteasar desires to find out what is the smallest number of wins that could provide the title of the lucky chap. Be a good fellow and help him satisfy his curiosity!


Write a programme that:

For each game played reads from the standard input the pair of players who competed in it.

Finds the smallest number kk, such that a set of games' outcomes exists in which each player wins kk games at the most,writes the number kk and the results of games in the found set to the standard output.

Input Format

In the first line of the standard input there is a pair of integers nn and mm separated by a single space, 1n100001\le n\le 10000, 0m100000\le m\le 10000; nn denotes the number of players, while mm is the number of games. The players are numbered from 11 to nn. In the following mm lines there are pairs of players' numbers depicting the sequence of games, separated by single spaces. One pair may occur many times in the sequence.

Output Format

The first line of the standard output should contain the determined number kk. For each pair of players' numbers aa, bb specified in the ii'th line of the input, in the ii'th line of the output the number 11 should be written if the player no. aa wins against player no. bb in the found set of outcomes, or 00 otherwise.

4 4
1 2
1 3
1 4
1 2
1
0
0
0
1

Hint