Answered step by step
Verified Expert Solution
Question
1 Approved Answer
***python*** This section of the assignment requires you to implement a method to find the girth of a digraph. You must implement your method from
***python***
This section of the assignment requires you to implement a method to find the girth
of a digraph. You must implement your method from first principles and cannot use an existing library method
that finds the girth.
Girth of a digraph For a digraph G, the length of the shortest cycle is called the directed girth of the graph. If the digraph has no cycle then the girth is undefined, and we will say it has girth 0. Your task is to determine the directed girth of each input digraph Input Format Input for this problem consists of a sequence of one or more digraphs taken from the keyboard (System.in). Each graph is represented by an adjacency list. The first line is an integer n indicating the order of the graph. This is followed by n white space separated lists of adjacencies for nodes labeled 0 ton- 1. The input will be terminated by a line consisting of one zero (0). This line should not be processed. Two sample input digraphs are listed below. The test cases are digraphs of order at most 30 4 1 3 2 3 0 1 2 0 OutputFormat Output will be just one integer per line sent to the console (e.g. System.out). For the above, input we would output the following two integers denoting the girth of the two graphs, using 0 to indicate the graph has no cycle 0 Girth of a digraph For a digraph G, the length of the shortest cycle is called the directed girth of the graph. If the digraph has no cycle then the girth is undefined, and we will say it has girth 0. Your task is to determine the directed girth of each input digraph Input Format Input for this problem consists of a sequence of one or more digraphs taken from the keyboard (System.in). Each graph is represented by an adjacency list. The first line is an integer n indicating the order of the graph. This is followed by n white space separated lists of adjacencies for nodes labeled 0 ton- 1. The input will be terminated by a line consisting of one zero (0). This line should not be processed. Two sample input digraphs are listed below. The test cases are digraphs of order at most 30 4 1 3 2 3 0 1 2 0 OutputFormat Output will be just one integer per line sent to the console (e.g. System.out). For the above, input we would output the following two integers denoting the girth of the two graphs, using 0 to indicate the graph has no cycle 0
Step 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