-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathg.cpp
More file actions
35 lines (31 loc) · 620 Bytes
/
Copy pathg.cpp
File metadata and controls
35 lines (31 loc) · 620 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<bits/stdc++.h>
using namespace std;
vector<int> adj[100005], dp(100005, -1);
int n, m, u, v, visited[100005];
void dfs(int node) {
visited[node] = 1;
for (int i = 0; i < adj[node].size(); i++) {
if (!visited[adj[node][i]])
dfs(adj[node][i]);
dp[node] = max(dp[node], dp[adj[node][i]] + 1);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> u >> v;
u--; v--;
adj[u].push_back(v);
}
for (int i = 0; i < n; i++) {
if (!visited[i])
dfs(i);
}
int ans = 0;
for (int e : dp) {
ans = max(ans, e);
}
cout << ans + 1;
}