Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Given an undirected graph G = ( V , E ) with n vertices and m edges, and a positive ( not necessarily unique )
Given an undirected graph G V E with n vertices and m edges, and a positive not necessarily unique edge cost ce for each edge in E We are also given q pairs of vertices Q u vuq vq Decide for each pair u v in Q if there is a path between u and v in G Task: Design an algorithm that solves this problem in Oq m n time. Implementation and Testing: Implement your algorithm in Ed and test it on the following graph instances: Graph Graph Graph Each instance is given as a text file using the following format: n m vertexId vertexId weight vertexId vertexId weight vertexId vertexId weight q vertexId vertexId vertexId vertexId For example, the text below describes the instance depicted in Fig. Note that the vertices are numbered from to n and that the two queries are and Your program should read input from the text file. Your program only needs to print out yes, there is a path in G between u and v or no there is no path connecting u and v in G for each of the q query pairs. You should separate each with a new line. A scaffold is provided for Python for you. Your code will not be benchmarked or tested for time complexity, but for full points it must be able to run instances similar to Graph and each test will time out after seconds. Your program will also be tested on several hidden test cases. If the query is on the figure below then the answer should be while the answer to the query on the same graph should be Below is the scaffold provided # Read in the number of vertices n and edges m n intinput m intinput edges, queries for in rangem: edges.appendinputsplit q intinput for in rangeq: queries.appendinputsplit # Print a to stdout for each query. This section should be altered to instead print a where the # query indicates a connection and else. for in queries: printintTrue
Given an undirected graph G V E with n vertices and m edges, and a positive
not necessarily unique edge cost ce for each edge in E We are also given q pairs
of vertices Q u vuq vq Decide for each pair u v in Q if there is a
path between u and v in G
Task: Design an algorithm that solves this problem in Oq m n time.
Implementation and Testing: Implement your algorithm in Ed and test it on
the following graph instances: Graph Graph Graph Each instance is
given as a text file using the following format:
n
m
vertexId vertexId weight
vertexId vertexId weight
vertexId vertexId weight
q
vertexId vertexId
vertexId vertexId
For example, the text below describes the instance depicted in Fig. Note that
the vertices are numbered from to n and that the two queries are and
Your program should read input from the text file. Your program only needs to
print out yes, there is a path in G between u and v or no there is no
path connecting u and v in G for each of the q query pairs. You should separate
each with a new line. A scaffold is provided for Python for you.
Your code will not be benchmarked or tested for time complexity, but for full
points it must be able to run instances similar to Graph and each test will
time out after seconds. Your program will also be tested on several hidden test
cases.
If the query is on the figure below then the answer should be while
the answer to the query on the same graph should be
Below is the scaffold provided
# Read in the number of vertices n and edges m
n intinput
m intinput
edges, queries
for in rangem:
edges.appendinputsplit
q intinput
for in rangeq:
queries.appendinputsplit
# Print a to stdout for each query. This section should be altered to instead print a where the
# query indicates a connection and else.
for in queries:
printintTrue
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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