Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 3: Snakes in a Graph For a graph G- (V, E), a snake (also called an induced path) is a path vi,v2,..., vk such

image text in transcribed

Task 3: Snakes in a Graph For a graph G- (V, E), a snake (also called an induced path) is a path vi,v2,..., vk such that for all j-i>1 (vi,vj) f E. That is, it is a sequence of vertices in G such that each two adjacent vertices in the sequence are connected by an edge in G, and each two nonadjacent vertices in the sequence are not connected by any edge in G For this task, our goal is to determine the largest snake of a graph Input Format Input for this problem consist of a sequence of one or more (undirected) graphs taken from the keyboard. 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 to n - 1. The input will be terminated by a line consisting of one zero (0). This line should not be processed. Two sample input graphs are listed below. The easy (harder) test cases are graphs of order at most 10 (50) 4 0 3 1 4 0 2 1 3 4 2 4 0 2 3 0 Output Format 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 longest snake of the two graphs. Recall that the length of a path is the number of edges 2 Task 3: Snakes in a Graph For a graph G- (V, E), a snake (also called an induced path) is a path vi,v2,..., vk such that for all j-i>1 (vi,vj) f E. That is, it is a sequence of vertices in G such that each two adjacent vertices in the sequence are connected by an edge in G, and each two nonadjacent vertices in the sequence are not connected by any edge in G For this task, our goal is to determine the largest snake of a graph Input Format Input for this problem consist of a sequence of one or more (undirected) graphs taken from the keyboard. 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 to n - 1. The input will be terminated by a line consisting of one zero (0). This line should not be processed. Two sample input graphs are listed below. The easy (harder) test cases are graphs of order at most 10 (50) 4 0 3 1 4 0 2 1 3 4 2 4 0 2 3 0 Output Format 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 longest snake of the two graphs. Recall that the length of a path is the number of edges 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 11G SQL

Authors: Joan Casteel

2nd Edition

1133947360, 978-1133947363

Students also viewed these Databases questions

Question

What benefits are we looking to gain by using external providers?

Answered: 1 week ago