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:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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≤ai,bi≤n) — the beginning and the finish of the I-th edge. The vertices of the diagram are numbered from 1 to n. The given diagram can contain circles (it is conceivable that ai=bi), yet can't contain multi-edges (it is unimaginable that ai=aj and bi=bj for i≠j). The amount of n over all experiments doesn't surpass 4⋅105. Essentially, the amount of m over all experiments doesn't surpass 4⋅105. 

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.

Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education