View difference between Paste ID: tRKN172U and f4keiVS2
SHOW: | | - or go back to the newest paste.
1
#include <iostream>
2
#include <fstream>
3
using namespace std;
4
5
int a[100][100], c[100], n, p, u, d[100];
6
bool viz[100];
7
ifstream f("graf.in");
8
9
void citire()
10
{
11
    int i, j;
12
    f>>n;
13
    while(f>>i>>j)
14
        a[i][j]=a[j][i]=1;
15
}
16
17
void lee(int start)
18
{
19
    p=u=1;
20
    int i, x;
21
    c[p]=start;
22
    viz[start]=true;
23
    while(p<=u)
24
    {
25
        x=c[p];
26
        for(i=1;i<=n;i++)
27
            if(a[i][x]==1 && viz[i]==false)
28
            {
29
                u++;
30
                c[u]=i;
31
                viz[i]=true;
32
                d[i]=d[x]+1;
33
            }
34
            p++;
35
    }
36
}
37
38
int main()
39
{
40
    citire();
41
    int nod1, nod2;
42
    cout<<"Nodurile pt calc drumului : "<<endl;
43
    cin>>nod1>>nod2;
44
    lee(nod1);
45
    cout<<"lungime: "<<d[nod2];
46
}
47
48
49
/*
50
fisier
51
7
52
1 2
53
1 4
54
2 4
55
1 5
56
5 6
57
6 3
58
3 7
59
*/