Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int c[100],a[100][100],n;
- bool viz[100];
- void citire(int a[100][100],int &n)
- {
- ifstream f("graf.in");
- int i,j;
- f>>n;
- for(i=1; i<=n; i++)
- for(j=1; j<=n; j++)
- f>>a[i][j];
- }
- int main()
- {
- int p,u,x,start,i;
- citire(a,n);
- p=u=1;
- cout<<"Nodul de start: ";
- cin>>start;
- c[p]=start;
- viz[start]=true;
- while(p<=u)
- {
- x=c[p];
- for(i=1; i<=n; i++)
- if(a[x][i]==1&& viz[i]==false)
- {
- viz[i]=true;
- u++;
- c[u]=i;
- }
- p++;
- }
- cout<<endl;
- for(i=1; i<=n; i++)
- cout<<c[i]<<" ";
- }
- /* graf.in
- 6
- 0 0 1 1 0 0
- 0 0 0 1 0 0
- 1 0 0 0 1 1
- 1 1 0 0 0 0
- 0 0 1 0 0 1
- 0 0 1 0 1 0
- */
Advertisement
Add Comment
Please, Sign In to add comment