Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void citire_graf(int a[][20], int n)
- {
- int i, j;
- for(i = 1; i <= n; i++)
- for(j = i + 1; j <= n; j++)
- {
- do
- {
- cout << "a[" << i << "," << j << "] = ";
- cin >> a[i][j];
- } while ((a[i][j]!=0) && (a[i][j]!=1));
- a[j][i] = a[i][j];
- }
- }
- void dfs(int start,int viz[],int a[][20], int p, int n)
- {
- int i;
- viz[start]=1;
- for(i=1;i<=n;i++)
- if(a[start][i]==1) {
- if(i != p && viz[i] == 1)
- a[0][0] = 1;
- if(viz[i] == 0)
- dfs(i,viz,a,start,n);
- }
- }
- int main()
- {
- int i,j,n,m;
- int a[20][20] = {0};
- int viz[20] = {0};
- cout << "N="; cin >> n;
- citire_graf(a,n);
- for( i = 1;i<=n;i++) {
- for(j=1;j<=n;j++)
- cout<<a[i][j] << " ";
- cout << "\n";
- }
- dfs(1,viz,a,1,n);
- cout << "\n";
- if(a[0][0] == 1)
- cout << "Are ciclu \n";
- else
- cout << "Nu are ciclu \n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement