During a programming contest, Mr. Search Tree (a.k.a. MST) forgot how to implement Kruskal's and Prim's algorithms. In a moment of desperation, he wrote a DFS that always follows the smallest available edge first. Strangely enough, it passed.
Now he wonders: for which starting nodes does his "Most Stupid Technique" accidentally produce a correct minimum spanning tree$$$^\dagger$$$ ?
Formally, given a connected undirected graph with $$$n$$$ nodes and $$$m$$$ edges, the $$$i$$$-th edge has weight $$$i$$$, and here is the algorithm he used:
vis := array of n booleans
s := set of edges
function dfs(u):
vis[u] := true
for each edge (u, v) connected to u in increasing order of edge weight:
if not vis[v]:
add edge (u, v) to s
dfs(v)
function findMST(u):
reset vis to all false
clear the edge set s
dfs(u)
return s
In other words, findMST(u) performs a DFS starting from vertex $$$u$$$, always choosing the smallest-weight unvisited edge from the current node and includes it in the tree.
Although this always produces a spanning tree, it doesn't always yield a minimum one.
Your task is to determine, for each node $$$i$$$ from $$$1$$$ to $$$n$$$, whether findMST(i) returns a minimum spanning tree.
$$$^\dagger$$$ A minimum spanning tree (MST) of a connected undirected graph is a subset of the edges that forms a tree connecting all the vertices and has the minimum possible total edge weight among all such trees.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 10^5, n - 1 \leq m \leq 2 \cdot 10^5$$$), denoting the number of vertices and edges.
For the following $$$m$$$ lines, the $$$i$$$-th line contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n, u_i \neq v_i$$$), denoting an undirected edge between $$$u_i$$$ and $$$v_i$$$.
The $$$i$$$-th edge ($$$1$$$-based index in input) has weight $$$i$$$.
It's guaranteed that the graph is connected and contains no duplicate edges.
Output one line containing a binary string of length $$$n$$$.
The i-th character should be '$$$1$$$'(without quotes) if the tree produced by running the algorithm above starting from node i is a minimum spanning tree, and '$$$0$$$'(without quotes) otherwise.
5 51 21 32 32 42 5
01111
8 91 26 73 73 55 81 42 42 31 6
00010100
The sample case is shown below:

The graph for the sample
The only minimum spanning tree (MST) of this graph includes the edges with weights $$$1$$$, $$$2$$$, $$$4$$$, and $$$5$$$, which has a total edge weight of 12.
We simulate the algorithm findMST(u) for each $$$u$$$ from $$$1$$$ to $$$5$$$:
Thus, the output is 01111.