Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <cmath>
- //#include "optimization.h"
- using namespace std;
- vector<int> used;
- void dfs(int v, vector<vector<int> > &g) {
- for (int u : g[v]) {
- if (!used[u]) {
- dfs(u, g);
- }
- used[v] = max(used[v], used[u]);
- }
- ++used[v];
- }
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int n, m;
- cin >> n >> m;
- vector<vector<int> > v(n);
- for (int i = 0; i < m; ++i) {
- int a, b;
- cin >> a >> b;
- --a;
- --b;
- v[a].push_back(b);
- }
- used.resize(n);
- for (int i = 0; i < n; ++i) {
- if (!used[i]) {
- dfs(i, v);
- }
- }
- cout << *max_element(used.begin(), used.end()) - 1;
- }
- /*
- 5 5
- 1 2
- 2 3
- 3 4
- 3 5
- 1 5
- */
- /*
- 4 2 1 1 4 2
- ..*.
- *...
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement