Graph Measurement
Time limit30sMemory limit512 MB
Given k random black/white colorings of an unknown graph's edges, recover the graph from the per-vertex counts of black edges.
- Level
Hard8 of 10
- Topics
- Probability, Math
- Solved
- No attempts yet
Statement
Andrew has a simple undirected graph on vertices (). The graph has no self-loops and no multiple edges. He repeats the following measurement times. For each edge, he colors it black or white independently, with probability 50% for each color. Then he counts the number of black edges adjacent to each vertex and tells you these numbers.
Your goal is to restore the original graph from the given numbers.
Input
The first line contains two integers and (in all cases except the sample, ). The next lines each contain integers. Line gives, for measurement , the number of black edges adjacent to each vertex, in vertex order.
Output
In the first line, print an integer , the number of edges in the graph. In the next lines, describe each edge by the two vertices it connects. Vertices are numbered from 1 to . There must be no self-loops, and at most one edge may connect any pair of vertices. The order of the edges and the order of the two vertices within each edge do not matter.
In the sample case, any valid graph is accepted, even if it is inconsistent with the input (for example, a graph with 0 edges). In all other cases, only the graph that actually generated the input is accepted.
Hints
Note that all cases except the sample have many measurements, specifically . There are 33 non-sample test cases.