Random Walking

Time limit1sMemory limit128 MB

Summary
For each graph, decide whether every bit position in every one of k random walk outputs has a 1-probability strictly between 25% and 75%.
Level

Medium7 of 10

Topics
Graph, Probability, Dynamic programming, Implementation
Solved
No attempts yet

Problem

The Army of Coin-tossing Monkeys (ACM) is in the business of producing randomness. Good random numbers matter for many applications: cryptography, online gambling, randomized algorithms, and last-second panic attempts at solutions during programming contests.

One of the best monkeys recently retired, but before leaving invented a cheaper way to generate randomness than reading coin tosses directly. The method starts from an undirected graph with 2n2^n nodes labelled 0,1,…,2n−10, 1, \ldots, 2^n - 1. To generate kk random nn-bit numbers, the monkeys toss nn coins to choose a starting node, and that node's number is the first output. They then pick a uniformly random edge incident to the current node and jump along it to the neighbouring node, whose number is the next output. From there they again pick a uniformly random incident edge (possibly the very edge they just arrived on), move, and output the node they land on. The walk continues until kk numbers have been output.

Different graphs produce different output distributions, and some are not very random. The ACM considers a graph good if, for every one of the nn bits in every one of the kk output numbers, the probability that the bit equals 11 is strictly greater than 25%25\% and strictly less than 75%75\%. Given a graph, decide whether it is good.

Input

The input contains several data sets. Each data set begins with a line of three space-separated integers kk, nn, ee, where kk is the count of nn-bit numbers to generate and ee is the number of edges, with 1≤k≤1001 \le k \le 100, 1≤n≤101 \le n \le 10, and 1≤e≤20001 \le e \le 2000. Each of the next ee lines contains two space-separated integers v1v_1 and v2v_2 with 0≤v1,v2<2n0 \le v_1, v_2 < 2^n and v1≠v2v_1 \ne v_2, describing an undirected edge. Every node is guaranteed to have at least one incident edge, and there may be multiple edges between the same pair of nodes.

The last data set is followed by a line with k=n=e=0k = n = e = 0, which must not be processed.

Output

For each data set, print a single line containing Yes if the graph is good, or No otherwise.

Examples1

  1. Example 1

    Input
    10 2 3
    0 3
    1 3
    2 3
    5 2 4
    0 1
    0 3
    1 2
    2 3
    0 0 0
    
    Expected output
    No
    Yes