Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- int G[100][100];
- int n;
- int st[100];
- int viz[100];
- int gasit=0;
- int nr=1;
- int read_data()
- {
- fstream f("input.in", ios::in);
- f>>n;
- for(int i=1; i<=n; i++)
- for(int j=1; j<=n; j++)f>>G[i][j];
- f.close();
- return 0;
- }
- int testing_cycle(int nod)
- {
- int last;
- int vf=1;
- st[vf]=nod;
- while(vf>=1)
- {
- viz[st[vf]]=1;
- for(int i=1; i<=n; i++)
- {
- if((G[st[vf]][i]==1)&&(viz[i]==0))
- {
- last=st[vf];
- vf++;
- st[vf]=i;
- viz[st[vf]]=1;
- for(int j=1; j<vf; j++)
- {
- if((G[st[vf]][j]==1)&&(viz[j]==1)&&(j!=last ))
- {
- return 1;
- }
- }
- }
- }
- break;
- }
- return 0;
- }
- int main()
- {
- read_data();
- int cycle=0;
- for(int i=1; i<=n; i++)
- {
- if(viz[i]!=1){cycle=cycle + testing_cycle(i);
- for(int j=1;j<=n;j++)viz[j]=0;
- }
- }
- cout<<cycle<<" ";
- if(cycle==0)cout<<"Nu contine cicluri";
- else cout<<"Contine cicluri";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement