Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A tree is an undirected graph that consists of N nodes and ) edges suchConstraints 2 N 1 0 ? ? 5 1 S e

A tree is an undirected graph that consists of N nodes and ) edges suchConstraints
2N10??5
1Se2N
1A[i]10???5
1edges[i][j]N
Sample testcases explanation
that there is exactly one path between each pair of nodes. A walk is a traversal
in the graph, which can be expressed as a sequence of nodes. Nodes and
edges can be repeated in the walk. Thus, we can say that a walk is a path that
allows you to repeat nodes and edges.
You are given a tree of N nodes. However, each node has a restriction that
allowsionte i to be visited at most A[i] times.
Your task is to find the length of the longest walk that starts in node S and
ends in S Since the answer might be large, return it modulo 10??9+7.
Input Format
The first line contains an integer, N, denoting the number of nodes.
The next dine contains an integer, S, denoting the node that you should start
and end the walk in
Each line i of the N subsequent lines (where 1iN) contains an integer
describing Ais
Each line iof the N-1 subsequent lines (where 0i
Please provide optimised code
image text in transcribed

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

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

He was not surprised at team s record. is the grammar correct.

Answered: 1 week ago