{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n section pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"Problem Statement","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eThere is a rooted tree (see Notes) with \u003cvar\u003e\\(N\\)\u003c/var\u003e vertices numbered \u003cvar\u003e\\(1\\)\u003c/var\u003e to \u003cvar\u003e\\(N\\)\u003c/var\u003e.\r\nEach of the vertices, except the root, has a directed edge coming from its parent.\r\nNote that the root may not be Vertex \u003cvar\u003e\\(1\\)\u003c/var\u003e.\u003c/p\u003e\r\n\u003cp\u003eTakahashi has added \u003cvar\u003e\\(M\\)\u003c/var\u003e new directed edges to this graph.\r\nEach of these \u003cvar\u003e\\(M\\)\u003c/var\u003e edges, \u003cvar\u003e\\(u \\rightarrow v\\)\u003c/var\u003e, extends from some vertex \u003cvar\u003e\\(u\\)\u003c/var\u003e to its descendant \u003cvar\u003e\\(v\\)\u003c/var\u003e.\u003c/p\u003e\r\n\u003cp\u003eYou are given the directed graph with \u003cvar\u003e\\(N\\)\u003c/var\u003e vertices and \u003cvar\u003e\\(N-1+M\\)\u003c/var\u003e edges after Takahashi added edges.\r\nMore specifically, you are given \u003cvar\u003e\\(N-1+M\\)\u003c/var\u003e pairs of integers, \u003cvar\u003e\\((A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M})\\)\u003c/var\u003e, which represent that the \u003cvar\u003e\\(i\\)\u003c/var\u003e-th edge extends from Vertex \u003cvar\u003e\\(A_i\\)\u003c/var\u003e to Vertex \u003cvar\u003e\\(B_i\\)\u003c/var\u003e.\u003c/p\u003e\r\n\u003cp\u003eRestore the original rooted tree.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Notes","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eFor \"tree\" and other related terms in graph theory, see \u003ca href\u003d\"https://ja.wikipedia.org/wiki/%E6%9C%A8_(%E6%95%B0%E5%AD%A6)\" target\u003d\"_blank\"\u003ethe article in Wikipedia\u003c/a\u003e, for example.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Constraints","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cul\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(3 \\leq N\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq M\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(N + M \\leq 10^5\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq A_i, B_i \\leq N\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(A_i \\neq B_i\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003eIf \u003cvar\u003e\\(i \\neq j\\)\u003c/var\u003e, \u003cvar\u003e\\((A_i, B_i) \\neq (A_j, B_j)\\)\u003c/var\u003e.\u003c/li\u003e\r\n\u003cli\u003eThe graph in input can be obtained by adding \u003cvar\u003e\\(M\\)\u003c/var\u003e edges satisfying the condition in the problem statement to a rooted tree with \u003cvar\u003e\\(N\\)\u003c/var\u003e vertices.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Input","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eInput is given from Standard Input in the following format:\u003c/p\u003e\r\n\u003cpre\u003e\u003cvar\u003e\\(N\\)\u003c/var\u003e \u003cvar\u003e\\(M\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(A_1\\)\u003c/var\u003e \u003cvar\u003e\\(B_1\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(:\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(A_{N-1+M}\\)\u003c/var\u003e \u003cvar\u003e\\(B_{N-1+M}\\)\u003c/var\u003e\r\n\u003c/pre\u003e\r\n\r\n\u003c/section\u003e\r\n"}},{"title":"Output","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003ePrint \u003cvar\u003e\\(N\\)\u003c/var\u003e lines.\r\nIn the \u003cvar\u003e\\(i\\)\u003c/var\u003e-th line, print \u003ccode\u003e0\u003c/code\u003e if Vertex \u003cvar\u003e\\(i\\)\u003c/var\u003e is the root of the original tree, and otherwise print the integer representing the parent of Vertex \u003cvar\u003e\\(i\\)\u003c/var\u003e in the original tree.\u003c/p\u003e\r\n\u003cp\u003eNote that it can be shown that the original tree is uniquely determined.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\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\u003e3 1\r\n1 2\r\n1 3\r\n2 3\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\r\n1\r\n2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003cp\u003eThe graph in this input is shown below:\u003c/p\u003e\r\n\u003cp\u003e\u003cimg alt\u003d\"\" src\u003d\"CDN_BASE_URL/9904578d8b0e7f36fbe6b556c60d1d8b?v\u003d1715282881\"\u003e\u003c/p\u003e\r\n\u003cp\u003eIt can be seen that this graph is obtained by adding the edge \u003cvar\u003e\\(1 \\rightarrow 3\\)\u003c/var\u003e to the rooted tree \u003cvar\u003e\\(1 \\rightarrow 2 \\rightarrow 3\\)\u003c/var\u003e.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 2","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\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 3\r\n2 1\r\n2 3\r\n4 1\r\n4 2\r\n6 1\r\n2 6\r\n4 6\r\n6 5\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e6\r\n4\r\n2\r\n0\r\n6\r\n2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\u003c/section\u003e\r\n"}}]}