Fredo and his Birthday Gift
Practice
4.5 (2 votes)
Approved
Bit manipulation
Dynamic programming
Graphs
Medium
Ready
Problem
88% Success 706 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

It was Fredo's birthday yesterday. He got a simple graph of N vertices and M edges as one of the birthday gifts. He has been bragging about his gift to all his friends. One of his friends asked him to do the following task on the graph:

For each of the vertices in the graph, find the maximum length simple path ending at that vertex.
Being unable to solve it himself, he asks you for help. Help Fredo!
Note: Length of a simple path= number of edges in the path.
A simple path is a path in a graph which does not have repeating vertices.

Input Format:

First line contains an integer T denoting the number of test cases.
First line of each test case consists of two space separated integers denoting N and M and the following M lines consist of two space separated integers X and Y denoting there is an edge between vertices X and Y.

Output Format:

For each test case, print for each vertex(starting from vertex 1) , length of the maximum length simple path ending at that vertex.

Constraints:
\( 1 \le T \le 10 \)
\( 1 \le N \le 15 \)
\( 0 \le M < N*(N-1)/2 \)
\( 1 \le X, Y \le N \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
ApprovedBit ManipulationDynamic ProgrammingGraphsMediumReady