Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream fin("graf.in");
- void Citire(int &n, int m[][100])
- {
- fin>>n;
- while(!fin.eof())
- {
- int x,y;
- fin>>x>>y;
- m[x][y]=1;
- m[y][x]=1;
- }
- fin.close();
- }
- void DFS(int m[][100], int *viz, int n, int nod)
- {
- viz[nod]=1;
- for(int i=1; i<=n; i++)
- if(m[nod][i] == 1 && viz[i] == 0)
- DFS(m, viz, n, i);
- }
- int Matrice(int n, int m[][100])
- {
- int s=0;
- for(int i=1; i<=n; i++)
- for(int j=1; j<=n; j++)
- s+=m[i][j];
- return s;
- }
- int main()
- {
- int n, m[100][100], viz[100]={0};
- Citire(n, m);
- viz[1]=1;
- DFS(m, viz, n, 1);
- int ok=1;
- for(int i=1; i<=n; i++)
- if(viz[i] == 0)
- {
- cout<<"Nu este conex => nu este arbore";
- ok=0;
- }
- if(ok == 1)
- if(Matrice(n, m) == 2*(n-1))
- cout<<"Este arbore";
- else
- cout<<"Nu are n-1 muchii => nu este arbore";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement