Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Enunt: Parcurgerea in adancime a unui graf
- [ "Depth First" ]
- */
- #include <iostream>
- #include <fstream>
- using namespace std;
- int a[10][10], n, i, j, p, viz[10];
- void citire();
- void DF(int j);
- int main()
- {
- citire();
- DF(p);
- return 0;
- }
- void citire()
- {
- ifstream f("citire.in");
- f>>n;
- for(i=1; i<=n; i++)
- for(j=1; j<=n; j++)
- f>>a[i][j];
- f>>p;
- f.close();
- }
- void DF(int p)
- {
- int j;
- cout<<p<<" ";
- viz[p]=1;
- for(j=1; j<=n; j++)
- if(a[p][j] == 1 && viz[j] == 0)
- {
- viz[j]=1;
- DF(j);
- }
- }
- /* citire.in */
- 6
- 0 1 0 1 0 0
- 1 0 1 0 0 1
- 0 1 0 1 0 1
- 1 0 1 0 1 0
- 0 0 1 1 0 0
- 0 1 1 0 0 0
- 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement