Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream f("matrice.txt");
- int n,i,j,a[20][20],v[20],coada[20],i_c,sf_c;
- void citire()
- {
- f>>n;
- while(f>>i>>j)
- {
- a[i][j]=1;
- a[j][i]=1;
- }
- }
- void afisare()
- {
- for(int i=1; i<=n; i++)
- {
- for (int j=1; j<=n; j++)
- {
- cout<<a[i][j]<<" ";
- }
- cout<<endl;
- }
- }
- void adancime(int nod)
- {
- cout<<nod<<" ";
- v[nod]=1;
- for(int i=1; i<=n; i++)
- {
- if(a[nod][i]==1 && v[i]==0)
- {
- adancime(i);
- }
- }
- }
- void latime(int nod)
- {
- coada[i_c]=nod;
- v[nod]=1;
- while(i_c<=sf_c)
- {
- i=1;
- while(i<=n)
- {
- if(a[coada[i_c]][i]&&v[i]==0)
- {
- sf_c++;
- coada[sf_c]=i;
- v[i]=1;
- }
- i++;
- }
- cout<<coada[i_c]<<" ";
- i_c++;
- }
- }
- void conexe()
- {
- for(int i=1; i<=n; i++)
- {
- if(v[i]==0)
- {
- adancime(i);
- cout<<endl;
- }
- }
- }
- int main()
- {
- citire();
- afisare();
- conexe();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement