-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathg.cpp
More file actions
45 lines (34 loc) · 641 Bytes
/
g.cpp
File metadata and controls
45 lines (34 loc) · 641 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
36
37
38
39
40
41
42
43
44
45
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
ll int INF = 1e17;
vector <int> adj[100005];
int dp[100005];
int dfs(int node)
{
if(dp[node] != -1)
return dp[node];
dp[node] = 0;
for(int i=0;i<adj[node].size();i++)
dp[node] = max(dp[node], dfs(adj[node][i]) + 1);
return dp[node];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(dp, -1, sizeof dp);
int n, m, x, y;
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>x>>y;
adj[x].push_back(y);
}
y = 0;
for(int i=1;i<=n;i++)
y = max(y, dfs(i));
cout<<y<<endl;
return 0;
}