Answered step by step
Verified Expert Solution
Question
1 Approved Answer
*Please wirte in java 8* Directed Acyclic Graphs Given a directed graph as an adjacency list, you need to determine whether it is acyclic or
*Please wirte in java 8*
Directed Acyclic Graphs
Given a directed graph as an adjacency list, you need to determine whether it is acyclic or not.
Input Format
- Each of the lines in the input contains two space-separated integers, s and d, that represents an edge from the node s to d.
Constraints
Node numbers are 0 based, i.e. if there n nodes, the nodes are numnered as 0,1,2,...,n-1.
Output Format
The output of the program is 0 or 1, depending on the result of the isDag() function. If it returns TRUE, output is 1, otherwise it is 0.
Sample Input 0
0 1 0 2 0 3 1 2 1 3 2 3 2 4 4 5 5 6
Sample Output 0
1
Explanation 0
The example graph in this example is
Since there is no cycle in the graph, the result is 1
1 0 N 2 4 4. 5 6 6 3 3 13 14 1 import java.io.*; 2 import java.math.*; 3 import java.security.*; 4 import java.text.*; 5 import java.util.*; 6 import java.util.concurrent.*; 7 import java.util. function.*; 8 import java.util.regex.*; 9 import java.util.stream.*; 10 11 public class Solution { 12 public static class DirectedGraph { /* Adjacency List representation of the given graph */ 15 private MapStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started