Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream fin ("inf.in");
- ofstream fout ("inf.out");
- int n,m,a[1001][1001],v[1001],d[1001],zi=0,k,c[1001];
- void citire()
- {
- fin>>n>>m;
- for(int p=1;p<=m;p++)
- {
- int i,j;
- a[i][j]=a[j][i]=1;
- }
- fin>>k;
- for(int p=1;p<=m;p++)
- {
- fin>>c[p];
- v[c[p]]=1;
- d[c[p]]=1;
- }
- }
- void bfs()
- {
- int st=1;dr=k;
- while(st<=dr)
- {
- int nod=c[st++];
- for(int i=1;i<=n;i++)
- if(a[nod][i]==1 && !v[i])
- {
- v[i]=1;
- c[++dr]=d[nod]+1;
- if(zi<d[i])
- zi=d[i];
- }
- fout<<zi;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement