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