#C6192. Minimum Number of Teams
Minimum Number of Teams
Minimum Number of Teams
You are given n resources (numbered from 1 to n) and m dependency relations between them. Each dependency is represented as a directed edge u → v, meaning that resource u should be completed before resource v can be processed.
The goal is to determine the minimum number of teams required to complete all the resources under the constraint that a resource can only be handled in a team after all its prerequisites have been completed by previous teams.
Formally, if we denote by $T$ the minimum number of teams, then $T$ is equal to the number of layers (or levels) in a topologically sorted order of the directed acyclic graph (DAG). In other words, if you process all resources in rounds where in each round you take all resources with no pending dependencies, then the number of rounds required is the minimum number of teams.
You can assume that the graph given as input is a DAG (i.e. no cycles exist).
inputFormat
The input is given on standard input and consists of:
- The first line contains two integers n and m ($1 \leq n \leq 10^5$, $0 \leq m \leq 10^5$), representing the number of resources and the number of dependencies.
- The next m lines each contain two integers u and v, indicating a dependency (resource u must be completed before resource v).
outputFormat
Output a single integer on standard output representing the minimum number of teams required to complete all resources.
## sample5 4
1 2
2 3
3 4
4 5
5