{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n div.illustration {\n float: right;\n padding-left: 20px;\n }\n div.illustration .illustration {\n width: 100%;\n border-radius: 4px;\n }\n pre {\n display: block;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n color: #333;\n word-break: break-all;\n word-wrap: break-word;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cp\u003eConsider an undirected graph on \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e vertices. A \u003cspan class\u003d\"tex2jax_process\"\u003e$k$\u003c/span\u003e-colouring of the graph is simply\n an assignment to each vertex one of the \u003cspan class\u003d\"tex2jax_process\"\u003e$k$\u003c/span\u003e colours. There are no other\n restrictions – two vertices can get the same colour even if\n they are connected by an edge.\u003c/p\u003e\n\n \u003cp\u003eYou are given two \u003cspan class\u003d\"tex2jax_process\"\u003e$k$\u003c/span\u003e-colourings \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$t$\u003c/span\u003e. You want to transform from the\n initial colouring \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e to\n the final colouring \u003cspan class\u003d\"tex2jax_process\"\u003e$t$\u003c/span\u003e\n step by step. In each step, each vertex may change its colour\n to one of its neighbours’ colour, or keep its current\n colour.\u003c/p\u003e\n\n \u003cp\u003eFormally, you are looking for a sequence of \u003cspan class\u003d\"tex2jax_process\"\u003e$k$\u003c/span\u003e-colourings \u003cspan class\u003d\"tex2jax_process\"\u003e$C_0, C_1, C_2, \\dots , C_\\ell $\u003c/span\u003e such\n that \u003cspan class\u003d\"tex2jax_process\"\u003e$C_0 \u003d s$\u003c/span\u003e,\n \u003cspan class\u003d\"tex2jax_process\"\u003e$C_\\ell \u003d t$\u003c/span\u003e, and every\n \u003cspan class\u003d\"tex2jax_process\"\u003e$C_ i(x)$\u003c/span\u003e equals\n either\u003c/p\u003e\n\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003e\u003cspan class\u003d\"tex2jax_process\"\u003e$C_{i-1}(x)$\u003c/span\u003e;\n or\u003c/p\u003e\n \u003c/li\u003e\n\n \u003cli\u003e\n \u003cp\u003e\u003cspan class\u003d\"tex2jax_process\"\u003e$C_{i-1}(y)$\u003c/span\u003e where\n \u003cspan class\u003d\"tex2jax_process\"\u003e$(x, y)$\u003c/span\u003e is an edge in\n the graph\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n\n \u003cp\u003eThe input graph is guaranteed to be connected and has no\n self loops. Determine whether it is possible to construct such\n a sequence, and output one if there is any. The sequence need\n not be the shortest as long as it uses at most \u003cspan class\u003d\"tex2jax_process\"\u003e$20\\, 000$\u003c/span\u003e steps.\u003c/p\u003e\n\n \u003cp\u003eFor example, suppose you need to start with the initial\n colouring on the left and end up with the final colouring on\n the right:\u003c/p\u003e\n\n \u003cdiv class\u003d\"figure\"\u003e\n \u003ccenter\u003e\n \u003cimg src\u003d\"CDN_BASE_URL/37b3f5ec30f21045fa872665c5b58303?v\u003d1719544408\" alt\u003d\"\\includegraphics[width\u003d.5\\textwidth ]{startend}\" style\u003d\"width:50.00%\"\u003e\n \u003c/center\u003e\n \u003c/div\u003e\n\n \u003cp\u003eOne solution is as follows:\u003c/p\u003e\n\n \u003cdiv class\u003d\"figure\"\u003e\n \u003ccenter\u003e\n \u003cimg src\u003d\"CDN_BASE_URL/8adb171e27b7fb021a8901f1c7463c7d?v\u003d1719544408\" alt\u003d\"\\includegraphics[width\u003d.5\\textwidth ]{transitions}\" style\u003d\"width:50.00%\"\u003e\n \u003c/center\u003e\n \u003c/div\u003e\n\n \u003ch2\u003eInput\u003c/h2\u003e\n\n \u003cp\u003eThe first line of input contains three integers \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e, \u003cspan class\u003d\"tex2jax_process\"\u003e$m$\u003c/span\u003e, and \u003cspan class\u003d\"tex2jax_process\"\u003e$k$\u003c/span\u003e. Here \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e is the number of vertices,\n \u003cspan class\u003d\"tex2jax_process\"\u003e$m$\u003c/span\u003e is the number of edges\n and \u003cspan class\u003d\"tex2jax_process\"\u003e$k$\u003c/span\u003e is the number of\n colours (\u003cspan class\u003d\"tex2jax_process\"\u003e$1 \\leq n, k \\leq\n 100$\u003c/span\u003e, \u003cspan class\u003d\"tex2jax_process\"\u003e$0 \\leq m \\leq {n\n \\choose 2}$\u003c/span\u003e). The second line of input contains\n \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e integers, each in the\n range \u003cspan class\u003d\"tex2jax_process\"\u003e$[0, k-1]$\u003c/span\u003e. They\n indicate the initial colouring. The third line of input\n contains \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e integers,\n each in the range \u003cspan class\u003d\"tex2jax_process\"\u003e$[0,\n k-1]$\u003c/span\u003e. They indicate the final colouring. Each of the\n following \u003cspan class\u003d\"tex2jax_process\"\u003e$m$\u003c/span\u003e lines\n contains two integers \u003cspan class\u003d\"tex2jax_process\"\u003e$x_\n i$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$y_ i$\u003c/span\u003e,\n representing an edge in the graph (\u003cspan class\u003d\"tex2jax_process\"\u003e$1 \\leq x_ i, y_ i \\leq n$\u003c/span\u003e).\u003c/p\u003e\n\n \u003cp\u003eThe input graph is connected. There are no self loops or\n multiple edges.\u003c/p\u003e\n\n \u003ch2\u003eOutput\u003c/h2\u003e\n\n \u003cp\u003eOutput \u003ctt class\u003d\"ttfamily\"\u003eImpossible\u003c/tt\u003e if there is no\n such sequence. Otherwise, output one or more lines describing a\n sequence of colouring \u003cspan class\u003d\"tex2jax_process\"\u003e$C_0, C_1,\n C_2, \\dots , C_\\ell $\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$\\ell \\leq 20\\, 000$\u003c/span\u003e). Each line\n contains \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e integers\n separated by a single space, describing the colouring. The\n first line indicates the initial colouring and the last line\n indicates the final colouring.\u003c/p\u003e\n\n \u003cp\u003eYou can use at most \u003cspan class\u003d\"tex2jax_process\"\u003e$20\\,\n 000$\u003c/span\u003e steps, therefore the output contains at most\n \u003cspan class\u003d\"tex2jax_process\"\u003e$20\\, 001$\u003c/span\u003e lines.\u003c/p\u003e\n\n \u003ch2\u003eSample 1\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e6 6 2\n0 1 0 1 1 1\n1 0 0 0 1 0\n1 2\n2 3\n3 5\n5 4\n4 6\n6 5\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0 1 0 1 1 1\n1 1 0 1 0 1\n1 1 0 0 1 0\n1 0 0 0 1 0\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n\n \u003ch2\u003eSample 2\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1 0 2\n0\n1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eImpossible\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n "}}]}