#C7551. Longest Acyclic Path
Longest Acyclic Path
Longest Acyclic Path
You are given a directed acyclic graph with n cities (numbered from 1 to n) and m one-way roads. Each road connects two cities. Your task is to determine the length of the longest path (in terms of number of edges) that does not revisit any city.
Note: The graph is guaranteed to be a Directed Acyclic Graph (DAG). The longest path is defined as the maximum number of roads one can traverse such that no city is visited more than once.
Input Format
The first line contains two integers, n and m, where n is the number of cities and m is the number of roads. The next m lines each contain two integers u and v, representing a one-way road from city u to city v.
Output Format
Output a single integer: the length of the longest acyclic path in the graph.
inputFormat
The input is read from stdin and has the following format:
n m u1 v1 u2 v2 ... um vm
Here, n is the number of nodes, m is the number of edges, and each of the following m lines contains two space-separated integers u and v which represent a road from city u to city v.
outputFormat
Print the length (an integer) of the longest acyclic path. The output is written to stdout.
## sample5 6
1 2
2 3
3 4
1 3
3 5
2 5
3
</p>