given a coordinated chart G which can contain circles (edges from a vertex to itself). Multi-edges are missing in G which implies that for every single arranged pair (u,v) exists all things considered one edge from u to v. Vertices are numbered from 1 to n. A way from u to v is a grouping of edges to such an extent that:
Correct answer will upvoted else downvoted.
You are given a coordinated chart G which can contain circles (edges from a vertex to itself). Multi-edges are missing in G which implies that for every single arranged pair (u,v) exists all things considered one edge from u to v. Vertices are numbered from 1 to n.
A way from u to v is a grouping of edges to such an extent that:
vertex u is the beginning of the principal edge in the way;
vertex v is the finish of the last edge in the way;
for all sets of neighboring edges next edge begins at the vertex that the past edge finishes on.
We will expect that the unfilled succession of edges is a way from one u to another.
For every vertex v output one of four qualities:
0, in case there are no ways from 1 to v;
1, in case there is just a single way from 1 to v;
2, in case there is more than one way from 1 to v and the number of ways is limited;
−1, if the number of ways from 1 to v is endless.
Input :The first contains an integer t (1≤t≤104) — the number of experiments in the input. Then, at that point, t experiments follow. Before each experiment, there is an unfilled line.
The main line of the experiment contains two integers n and m (1≤n≤4⋅105,0≤m≤4⋅105) — numbers of vertices and edges in diagram separately. The following m lines contain edges portrayals. Each line contains two integers computer based intelligence, bi (1≤
Output :Output t lines. The I-th line ought to contain a response for the I-th experiment: a grouping of n integers from −1 to 2.
Step by step
Solved in 4 steps with 2 images