Dividing the Kingdom

3

3 votes
Dynamic Programming, Tree, Graphs, Algorithms, Depth First Search
Problem

There is a kingdom with N towns and N1 bidirectional roads, such that there is a direct path between every pair of towns. The king wants to divide the kingdom into set of roads where each town is an endpoint of atmost one edge. It means that no two roads should share a town between them. Find the maximum number of sets that the kingdom can be divided into.

Input Format:

The first input line contains an integer N: the number of nodes. The nodes are numbered 1,2,3,...,N
Then there are N1 lines describing the edges. Each line contains two integers a and b: there is an edge between nodes a and b.

Output Format:

Print one integer, the maximum number of sets that the kingdom can be divided into.

Constraints:

1N21051a,bN

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

One possible division can be :- (1,2) & (3,4)

Editor Image

?