-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatDPG.cpp
More file actions
45 lines (33 loc) · 763 Bytes
/
Copy pathatDPG.cpp
File metadata and controls
45 lines (33 loc) · 763 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
/*
* Contest : AtCoder Educational DP Contest
* Problem : G - Longest Path
* Link : https://atcoder.jp/contests/dp/tasks/dp_g
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
vector<vector<int>> adj;
vector<int> dist;
int dfs(int no) {
if (dist[no]) return dist[no];
int longest = 0;
for (auto &v : adj[no]) longest = max(longest, dfs(v));
return dist[no] = longest + 1;
}
int main() {
fastio
int n, m;
cin >> n >> m;
adj.resize(n + 1);
dist.assign(n + 1, false);
while (m--) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
}
int ans = 0;
for (int i = 1; i <= n; ++i) ans = max(ans, dfs(i));
cout << ans - 1 << '\n';
return 0;
}