Simulate the smallest-first label-flipping process on the graph and print every place with its final label.
Medium5SimulationGraphNo attempts yetTime limit2sMemory limit256 MBThe organizing committee of a motorcycle race labels the contest map. The map has n places numbered 0 through n−1. Every road is bidirectional and joins two different places.
Each place gets the label 0 for regular or 1 for service. If di roads reach place i, then at most ⌊di/2⌋ of its neighbors may carry the same label as place i. Several labelings usually satisfy that rule, so only the labeling produced by the following procedure counts as correct.
Each flip raises the number of roads whose two ends carry different labels by at least 1, so the procedure always stops after finitely many flips.
The first line contains the number of places n. (1≤n≤1000)
Each of the next n lines describes one place, line i describing place i. (i=0,1,…,n−1) A line has this form.
number_of_neighbors: neighbor1 neighbor2 ... neighborm
number_of_neighbors is the number of roads reaching place i, followed by the numbers of the neighboring places separated by spaces. The line 2: 1 2 means two neighbors, numbered 1 and 2.
No road joins a place to itself, and two places are joined by at most one road. If b appears in the neighbor list of place a, then a appears in the neighbor list of place b. The line of a place with no neighbor ends right after the colon.
Print n on the first line. Then print n lines, one per place starting from place 0, each carrying the label the procedure produced. A line has this form.
label number_of_neighbors: neighbor1 neighbor2 ... neighborm
label is 0 for a regular place and 1 for a service place. Print the neighbor list in the order it was given in the input. Separate tokens with one space, and put the colon directly after number_of_neighbors. The line of a place with no neighbor ends right after the colon.