Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- int n,A[101][101],m,v[101],nr,viz[101];
- bool ok;
- void citire()
- {
- int x,y;
- cin>>n>>m;
- for(int i=1;i<=m;i++)
- {
- cin>>x>>y;
- A[x][y]=1;
- }
- }
- void DFS(int x)
- {
- viz[x] = 1;
- v[x]++;
- for(int i=1; i<=n; i++)
- if(A[x][i] && !viz[i])
- DFS(i);
- }
- int main()
- {
- int i;
- citire();
- for (i=1; i<=n; i++)
- {
- DFS(i);
- memset(viz,0,sizeof(viz));
- }
- for (i=1; i<=n; i++)
- if (v[i]==n)
- {
- cout<<i;
- break;
- }
- if (i==n+1)
- cout<<"NU EXISTA";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement