Se citeste un graf si se verifica daca acesta este ARBORE.
|
#include<iostream>
#include<fstream> using namespace std; int s[50],A[50][50],n; void CitireN(char Nume_fis[20],int A[50][50],int& n) { int i,j; fstream f(Nume_fis,ios::in); f>>n; while(f>>i>>j) A[i][j]=A[j][i]=1; f.close(); } void df_r(int nod) { int k; s[nod]=1; for(k=1;k<=n;k++) if(A[nod][k]==1 && s[k]==0) { cout<<nod<<" "<<k<<endl; df_r(k); } } main() { CitireN("Graf.txt",A,n); df_r(1); } 5 1 2 2 3 2 4 2 5 3 5 4 5 1 3 |