{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e Here\u0027s a (un)classic problem.\u003c/p\u003e \n\u003cp\u003e You are given a weighted undirected graph on \u003cspan\u003e\u003ci\u003en\u003c/i\u003e\u003c/span\u003e vertices and \u003cspan\u003e\u003ci\u003em\u003c/i\u003e\u003c/span\u003e edges. Find the shortest path from vertex \u003cspan\u003e\u003ci\u003es\u003c/i\u003e\u003c/span\u003e to vertex \u003cspan\u003e\u003ci\u003et\u003c/i\u003e\u003c/span\u003e or else state that such path doesn\u0027t exist.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003e The first line of the input contains two space-separated integers — \u003cspan\u003e\u003ci\u003en\u003c/i\u003e\u003c/span\u003e and \u003cspan\u003e\u003ci\u003em\u003c/i\u003e\u003c/span\u003e (\u003cspan\u003e1 ≤ \u003ci\u003en\u003c/i\u003e ≤ 10\u003csup\u003e5\u003c/sup\u003e\u003c/span\u003e; \u003cspan\u003e0 ≤ \u003ci\u003em\u003c/i\u003e ≤ 10\u003csup\u003e5\u003c/sup\u003e\u003c/span\u003e).\u003c/p\u003e \n\u003cp\u003e Next \u003cspan\u003e\u003ci\u003em\u003c/i\u003e\u003c/span\u003e lines contain the description of the graph edges. The \u003cspan\u003e\u003cspan\u003e\u003ci\u003ei\u003c/i\u003e\u003c/span\u003e-th\u003c/span\u003e line contains three space-separated integers — \u003cspan\u003e\u003cspan\u003e\u003ci\u003eu\u003c/i\u003e\u003csub\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e\u003c/span\u003e, \u003cspan\u003e\u003ci\u003ev\u003c/i\u003e\u003csub\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e, \u003cspan\u003e\u003cspan\u003e\u003ci\u003ex\u003c/i\u003e\u003csub\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e\u003c/span\u003e (\u003cspan\u003e1 ≤ \u003cspan\u003e\u003ci\u003eu\u003c/i\u003e\u003csub\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e, \u003ci\u003ev\u003c/i\u003e\u003csub\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e ≤ \u003ci\u003en\u003c/i\u003e\u003c/span\u003e; \u003cspan\u003e0 ≤ \u003cspan\u003e\u003ci\u003ex\u003c/i\u003e\u003csub\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e ≤ 10\u003csup\u003e5\u003c/sup\u003e\u003c/span\u003e). \u003cspan\u003eThat means that vertices with numbers \u003cspan\u003e\u003cspan\u003e\u003ci\u003eu\u003c/i\u003e\u003csub\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e\u003c/span\u003e and \u003cspan\u003e\u003ci\u003ev\u003c/i\u003e\u003csub\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e are connected by edge of length \u003cspan\u003e\u003cspan\u003e2\u003csup\u003e\u003ci\u003ex\u003c/i\u003e\u003csub\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/sup\u003e\u003c/span\u003e\u003c/span\u003e (2 to the power of \u003cspan\u003e\u003cspan\u003e\u003ci\u003ex\u003c/i\u003e\u003csub\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e\u003c/span\u003e).\u003c/span\u003e\u003c/p\u003e \n\u003cp\u003e The last line contains two space-separated integers — the numbers of vertices \u003cspan\u003e\u003ci\u003es\u003c/i\u003e\u003c/span\u003e and \u003cspan\u003e\u003ci\u003et\u003c/i\u003e\u003c/span\u003e.\u003c/p\u003e \n\u003cp\u003e The vertices are numbered from \u003cspan\u003e1\u003c/span\u003e to \u003cspan\u003e\u003ci\u003en\u003c/i\u003e\u003c/span\u003e. The graph contains no multiple edges and self-loops.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003e In the first line print the remainder after dividing the length of the shortest path by \u003cspan\u003e1000000007\u0026nbsp;(10\u003csup\u003e9\u003c/sup\u003e + 7)\u003c/span\u003e if the path exists, and \u003cspan\u003e-1\u003c/span\u003e if the path doesn\u0027t exist.\u003c/p\u003e \n\u003cp\u003e If the path exists print in the second line integer \u003cspan\u003e\u003ci\u003ek\u003c/i\u003e\u003c/span\u003e — the number of vertices in the shortest path from vertex \u003cspan\u003e\u003ci\u003es\u003c/i\u003e\u003c/span\u003e to vertex \u003cspan\u003e\u003ci\u003et\u003c/i\u003e\u003c/span\u003e; in the third line print \u003cspan\u003e\u003ci\u003ek\u003c/i\u003e\u003c/span\u003e space-separated integers — the vertices of the shortest path in the visiting order. The first vertex should be vertex \u003cspan\u003e\u003ci\u003es\u003c/i\u003e\u003c/span\u003e, the last vertex should be vertex \u003cspan\u003e\u003ci\u003et\u003c/i\u003e\u003c/span\u003e. If there are multiple shortest paths, print any of them.\u003c/p\u003e"}},{"title":"Example","value":{"format":"HTML","content":"\u003cdiv\u003e \n \u003cdiv\u003e\n Input\n \u003c/div\u003e \n \u003cpre\u003e\r\n\t4 4\r\n1 4 2\r\n1 2 0\r\n2 3 0\r\n3 4 0\r\n1 4\r\n\u003c/pre\u003e \n\u003c/div\u003e \n\u003cdiv\u003e \n \u003cdiv\u003e\n Output\n \u003c/div\u003e \n \u003cpre\u003e\r\n\t3\r\n4\r\n1 2 3 4 \r\n\u003c/pre\u003e \n\u003c/div\u003e \n\u003cdiv\u003e \n \u003cdiv\u003e\n Input\n \u003c/div\u003e \n \u003cpre\u003e\r\n\t4 3\r\n1 2 4\r\n2 3 5\r\n3 4 6\r\n1 4\r\n\u003c/pre\u003e \n\u003c/div\u003e \n\u003cdiv\u003e \n \u003cdiv\u003e\n Output\n \u003c/div\u003e \n \u003cpre\u003e\r\n\t112\r\n4\r\n1 2 3 4 \r\n\u003c/pre\u003e \n\u003c/div\u003e \n\u003cdiv\u003e \n \u003cdiv\u003e\n Input\n \u003c/div\u003e \n \u003cpre\u003e\r\n\t4 2\r\n1 2 0\r\n3 4 1\r\n1 4\r\n\u003c/pre\u003e \n\u003c/div\u003e \n\u003cdiv\u003e \n \u003cdiv\u003e\n Output\n \u003c/div\u003e \n \u003cpre\u003e\r\n\t-1\r\n\u003c/pre\u003e \n\u003c/div\u003e"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cp\u003e A \u003cspan\u003epath\u003c/span\u003e from vertex \u003cspan\u003e\u003ci\u003es\u003c/i\u003e\u003c/span\u003e to vertex \u003cspan\u003e\u003ci\u003et\u003c/i\u003e\u003c/span\u003e is a sequence \u003cspan\u003e\u003cspan\u003e\u003ci\u003ev\u003c/i\u003e\u003csub\u003e0\u003c/sub\u003e\u003c/span\u003e\u003c/span\u003e, ..., \u003cspan\u003e\u003cspan\u003e\u003ci\u003ev\u003c/i\u003e\u003csub\u003e\u003ci\u003ek\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e\u003c/span\u003e, such that \u003cspan\u003e\u003cspan\u003e\u003ci\u003ev\u003c/i\u003e\u003csub\u003e0\u003c/sub\u003e\u003c/span\u003e \u003d \u003ci\u003es\u003c/i\u003e\u003c/span\u003e, \u003cspan\u003e\u003cspan\u003e\u003ci\u003ev\u003c/i\u003e\u003csub\u003e\u003ci\u003ek\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e \u003d \u003ci\u003et\u003c/i\u003e\u003c/span\u003e, and for any \u003cspan\u003e\u003ci\u003ei\u003c/i\u003e\u003c/span\u003e from 0 to \u003cspan\u003e\u003ci\u003ek\u003c/i\u003e - 1\u003c/span\u003e vertices \u003cspan\u003e\u003ci\u003ev\u003c/i\u003e\u003csub\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e and \u003cspan\u003e\u003ci\u003ev\u003c/i\u003e\u003csub\u003e\u003ci\u003ei\u003c/i\u003e + 1\u003c/sub\u003e\u003c/span\u003e are connected by an edge.\u003c/p\u003e \n\u003cp\u003e The \u003cspan\u003elength\u003c/span\u003e of the path is the sum of weights of edges between \u003cspan\u003e\u003ci\u003ev\u003c/i\u003e\u003csub\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e and \u003cspan\u003e\u003ci\u003ev\u003c/i\u003e\u003csub\u003e\u003ci\u003ei\u003c/i\u003e + 1\u003c/sub\u003e\u003c/span\u003e for all \u003cspan\u003e\u003ci\u003ei\u003c/i\u003e\u003c/span\u003e from 0 to \u003cspan\u003e\u003ci\u003ek\u003c/i\u003e - 1\u003c/span\u003e.\u003c/p\u003e \n\u003cp\u003e The \u003cspan\u003eshortest path\u003c/span\u003e from \u003cspan\u003e\u003ci\u003es\u003c/i\u003e\u003c/span\u003e to \u003cspan\u003e\u003ci\u003et\u003c/i\u003e\u003c/span\u003e is the path which length is minimum among all possible paths from \u003cspan\u003e\u003ci\u003es\u003c/i\u003e\u003c/span\u003e to \u003cspan\u003e\u003ci\u003et\u003c/i\u003e\u003c/span\u003e.\u003c/p\u003e"}}]}