Advertisement
Guest User

Sugi Pula Macaz

a guest
Jan 28th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int n,A[101][101],m,v[101],nr,viz[101];
  6. bool ok;
  7. void citire()
  8. {
  9. int x,y;
  10. cin>>n>>m;
  11. for(int i=1;i<=m;i++)
  12. {
  13. cin>>x>>y;
  14. A[x][y]=1;
  15. }
  16.  
  17. }
  18.  
  19. void DFS(int x)
  20. {
  21. viz[x] = 1;
  22. v[x]++;
  23. for(int i=1; i<=n; i++)
  24. if(A[x][i] && !viz[i])
  25. DFS(i);
  26. }
  27.  
  28. int main()
  29. {
  30. int i;
  31. citire();
  32. for (i=1; i<=n; i++)
  33. {
  34. DFS(i);
  35. memset(viz,0,sizeof(viz));
  36. }
  37. for (i=1; i<=n; i++)
  38. if (v[i]==n)
  39. {
  40. cout<<i;
  41. break;
  42. }
  43.  
  44. if (i==n+1)
  45. cout<<"NU EXISTA";
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement