Broken Tree
InterviewTime limit1sMemory limit512 MB
Given a tree whose edges are oriented, flip as few edges as possible so that some vertex can reach every other vertex.
Problem
A greedy panda gnawed on a tree, and now the tree is broken!
The input gives a directed graph. Turning every edge of this graph into a bidirectional edge yields a tree.
You may flip the direction of any edge. Your goal is to flip as few edges as possible so that there exists a vertex satisfying the following.
Every vertex is reachable from this vertex.
Input
The first line gives the number of vertices .
The next lines each give two integers . This means an edge directed from vertex to vertex . ,
Vertices are numbered from to . It is guaranteed that turning every edge of the graph into a bidirectional edge yields a tree.
Output
On the first line, output the edges that must be flipped as an -digit binary number. The -th bit from the left is 1 if the -th edge must be flipped, and 0 otherwise. The number of 1s appearing in the binary number must be minimized.
If there are multiple valid answers, output any one of them.