Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<ctime>
- #include<map>
- #include<vector>
- #include<queue>
- using namespace std;
- int n;
- int m;
- vector<int>graph[100005];
- int dp[100005];
- int rec(int i=0){
- if(dp[i]!=-1){
- return(dp[i]);
- }
- int result=0;
- for(int j=0; j<graph[i].size(); j++){
- result=max(result, rec(graph[i][j])+1);
- }
- dp[i] = result;
- return(result);
- }
- int main()
- {
- cin>>n;
- cin>>m;
- for(int i=0; i<m; i++){
- int a;
- int b;
- cin>>a>>b;
- graph[a].push_back(b);
- }
- for(int i=0; i<=n; i++){
- dp[i]=-1;
- }
- int result1=0;
- for(int i=0; i<=n; i++){
- result1=max(result1, rec(i));
- }
- cout<<result1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement