Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define MAXN 1000
- using namespace std;
- int U[MAXN+1], S[MAXN], P[MAXN], G[MAXN][MAXN];
- int maxPath // = 0, currentPath = 0;
- int N,M;
- void DFS_R(int r)
- {
- int y;
- while(G[r][0]>0)
- {
- y=G[r][G[r][0]--];
- if(!U[y]) { U[y]=1; P[y]=r; DFS_R(y); }
- }
- maxPath++;
- // if( currentPath > maxPath ){
- // maxPath = currentPath;
- // }
- // currentPath++;
- }
- void first_call()
- {
- for(int i=1;i<=N;i++) U[i]=0; maxPath=0;
- for(int i=1;i<=N;i++) if(U[i]==0) DFS_R(i);
- }
- int main()
- {
- int x,y,i;
- cin >> N >> M;
- for(i=1;i<=N;i++) G[i][0]=0;
- for(i=1;i<=M;i++)
- {
- cin >> x >> y;
- G[x][++G[x][0]]=y;
- }
- first_call();
- cout << maxPath << endl;
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment