Apple OA question | August 2022

Правка en2, от achyut.jagini, 2022-08-06 20:21:47

given — integer N number of nodes
2D array of size (N-1)*2

edges of unweighted tree
no cycles
for each node determine number of paths containing node.
example for graph with edges 1-2 and 2-3

all paths — (1,2),(1,2,3),(2,3),(3,2),(3,2,1),(2,1)
node 1-4 times
node 2-6 times
node 3-4 times

so output is 4 6 4

Input format
1st line-no of testcases
2nd line -no of nodes(N)
next N lines 2 integers denoting source and destination vertex

Sample input
2
3
1 2
2 3
2
1 2

sample output
4 6 4
2 2

function
def count_paths(N,edges)

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский achyut.jagini 2022-08-06 20:21:47 40
en1 Английский achyut.jagini 2022-08-06 19:43:30 691 Initial revision (published)