{"raw_statement":[{"iden":"problem statement","content":"You are given a simple connected undirected graph with $N$ vertices and $M$ edges (a simple graph contains no self-loop and no multi-edges).  \nFor $i = 1, 2, \\ldots, M$, the $i$\\-th edge connects vertex $u_i$ and vertex $v_i$ bidirectionally.\nDetermine whether there is a way to paint each vertex black or white to satisfy both of the following conditions, and show one such way if it exists.\n\n*   At least one vertex is painted black.\n*   For every $i = 1, 2, \\ldots, K$, the following holds:\n    *   the minimum distance between vertex $p_i$ and a vertex painted black is exactly $d_i$.\n\nHere, the distance between vertex $u$ and vertex $v$ is the minimum number of edges in a path connecting $u$ and $v$."},{"iden":"constraints","content":"*   $1 \\leq N \\leq 2000$\n*   $N-1 \\leq M \\leq \\min\\lbrace N(N-1)/2, 2000 \\rbrace$\n*   $1 \\leq u_i, v_i \\leq N$\n*   $0 \\leq K \\leq N$\n*   $1 \\leq p_1 \\lt p_2 \\lt \\cdots \\lt p_K \\leq N$\n*   $0 \\leq d_i \\leq N$\n*   The given graph is simple and connected.\n*   All values in the input are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$ $M$\n$u_1$ $v_1$\n$u_2$ $v_2$\n$\\vdots$\n$u_M$ $v_M$\n$K$\n$p_1$ $d_1$\n$p_2$ $d_2$\n$\\vdots$\n$p_K$ $d_K$"},{"iden":"sample input 1","content":"5 5\n1 2\n2 3\n3 1\n3 4\n4 5\n2\n1 0\n5 2"},{"iden":"sample output 1","content":"Yes\n10100\n\nOne way to satisfy the conditions is to paint vertices $1, 3$ black and vertices $2, 4, 5$ white.  \nIndeed, for each $i = 1, 2, 3, 4, 5$, let $A_i$ denote the minimum distance between vertex $i$ and a vertex painted black, and we have $(A_1, A_2, A_3, A_4, A_5) = (0, 1, 0, 1, 2)$, where $A_1 = 0, A_5 = 2$."},{"iden":"sample input 2","content":"5 5\n1 2\n2 3\n3 1\n3 4\n4 5\n5\n1 1\n2 1\n3 1\n4 1\n5 1"},{"iden":"sample output 2","content":"No\n\nThere is no way to satisfy the conditions by painting each vertex black or white, so you should print `No`."},{"iden":"sample input 3","content":"1 0\n0"},{"iden":"sample output 3","content":"Yes\n1"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}