achyut.jagini's blog

By achyut.jagini, history, 10 days ago, In English

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)

 
 
 
 
  • Vote: I like it
  • +1
  • Vote: I do not like it

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

What are the constraints?

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by achyut.jagini (previous revision, new revision, compare).