{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"We will use the following (standard) definitions from graph theory. Let \u003ci\u003eV\u003c/i\u003e be a nonempty and finite set, its elements being called vertices (or nodes). Let \u003ci\u003eE\u003c/i\u003e be a subset of the Cartesian product \u003ci\u003eV×V\u003c/i\u003e, its elements being called edges. Then \u003ci\u003eG\u003d(V,E)\u003c/i\u003e is called a directed graph.\r\u003cbr\u003eLet \u003ci\u003en\u003c/i\u003e be a positive integer, and let \u003ci\u003ep\u003d(e\u003csub\u003e1\u003c/sub\u003e,...,e\u003csub\u003en\u003c/sub\u003e)\u003c/i\u003e be a sequence of length \u003ci\u003en\u003c/i\u003e of edges \u003ci\u003ee\u003csub\u003ei\u003c/sub\u003e∈E\u003c/i\u003e such that \u003ci\u003ee\u003csub\u003ei\u003c/sub\u003e\u003d(v\u003csub\u003ei\u003c/sub\u003e,v\u003csub\u003ei+1\u003c/sub\u003e)\u003c/i\u003e for a sequence of vertices \u003ci\u003e(v\u003csub\u003e1\u003c/sub\u003e,...,v\u003csub\u003en+1\u003c/sub\u003e)\u003c/i\u003e. Then \u003ci\u003ep\u003c/i\u003e is called a path from vertex \u003ci\u003ev\u003csub\u003e1\u003c/sub\u003e\u003c/i\u003e to vertex \u003ci\u003ev\u003csub\u003en+1\u003c/sub\u003e\u003c/i\u003e in \u003ci\u003eG\u003c/i\u003e and we say that \u003ci\u003ev\u003csub\u003en+1\u003c/sub\u003e\u003c/i\u003e is reachable from \u003ci\u003ev\u003csub\u003e1\u003c/sub\u003e\u003c/i\u003e, writing \u003ci\u003e(v\u003csub\u003e1\u003c/sub\u003e→v\u003csub\u003en+1\u003c/sub\u003e)\u003c/i\u003e.\r\u003cbr\u003eHere are some new definitions. A node \u003ci\u003ev\u003c/i\u003e in a graph \u003ci\u003eG\u003d(V,E)\u003c/i\u003e is called a sink, if for every node \u003ci\u003ew\u003c/i\u003e in \u003ci\u003eG\u003c/i\u003e that is reachable from \u003ci\u003ev\u003c/i\u003e, \u003ci\u003ev\u003c/i\u003e is also reachable from \u003ci\u003ew\u003c/i\u003e. The bottom of a graph is the subset of all nodes that are sinks, i.e., \u003ci\u003ebottom(G)\u003d{v∈V|∀w∈V:(v→w)⇒(w→v)}\u003c/i\u003e. You have to calculate the bottom of certain graphs."}},{"title":"Input","value":{"format":"HTML","content":"The input contains several test cases, each of which corresponds to a directed graph \u003ci\u003eG\u003c/i\u003e. Each test case starts with an integer number \u003ci\u003ev\u003c/i\u003e, denoting the number of vertices of \u003ci\u003eG\u003d(V,E)\u003c/i\u003e, where the vertices will be identified by the integer numbers in the set \u003ci\u003eV\u003d{1,...,v}\u003c/i\u003e. You may assume that \u003ci\u003e1\u0026lt;\u003dv\u0026lt;\u003d5000\u003c/i\u003e. That is followed by a non-negative integer \u003ci\u003ee\u003c/i\u003e and, thereafter, \u003ci\u003ee\u003c/i\u003e pairs of vertex identifiers \u003ci\u003ev\u003csub\u003e1\u003c/sub\u003e,w\u003csub\u003e1\u003c/sub\u003e,...,v\u003csub\u003ee\u003c/sub\u003e,w\u003csub\u003ee\u003c/sub\u003e\u003c/i\u003e with the meaning that \u003ci\u003e (v\u003csub\u003ei\u003c/sub\u003e,w\u003csub\u003ei\u003c/sub\u003e)∈E\u003c/i\u003e. There are no edges other than specified by these pairs. The last test case is followed by a zero."}},{"title":"Output","value":{"format":"HTML","content":"For each test case output the bottom of the specified graph on a single line. To this end, print the numbers of all nodes that are sinks in sorted order separated by a single space character. If the bottom is empty, print an empty line. \u003cimg src\u003d\"CDN_BASE_URL/707381fc711eb3b9ff89204aca2843e7?v\u003d1714201542\" align\u003d\"right\"\u003e"}},{"title":"Sample","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 3\r\n1 3 2 3 3 1\r\n2 1\r\n1 2\r\n0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1 3\r\n2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}