Editorial for COCI '13 Contest 4 #3 Sumo
Submitting an official solution before solving the problem yourself is a bannable offence.
Firstly, we need to know the answer to the following question. For a given , is it possible to divide the fighters into two teams so that in the first 
 fights there are no confrontations of fighters from the same team?
Actually, we need to check whether a graph with  nodes (which represent fighters) and 
 edges (which represent fights) is bipartite. In other words, is it possible to paint its nodes with two colors so that the adjacent nodes are of different colors? We check this by actually painting the nodes: starting from node 
, we paint it white, then paint its neighbors black (because we have to), then paint its neighbors white (because we have to) and so on. This painting is done with BFS or DFS algorithm. The algorithm ends when we have either successfully painted all the nodes, which means the painting can be done, or when we've come across a contradiction: an adjacent node of the node 
 from which we're currently expanding is already painted the same color as 
, which means the painting is not possible.
Now it is clear that we are looking for the smallest  for which this procedure is going to fail. Testing out all possible 
 numbers is too slow. That is why we use binary search to find the value of the number 
.
Comments
Would the selection of BFS or DFS result in different outcomes if the adajency list for each vertex is built as the edges are processed from the input? Can someone explain how a binary search is needed for this?