Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream fin ("inf.in");
  4. ofstream fout ("inf.out");
  5. int n,m,a[1001][1001],v[1001],d[1001],zi=0,k,c[1001];
  6. void citire()
  7. {
  8. fin>>n>>m;
  9. for(int p=1;p<=m;p++)
  10. {
  11. int i,j;
  12. a[i][j]=a[j][i]=1;
  13. }
  14. fin>>k;
  15. for(int p=1;p<=m;p++)
  16. {
  17. fin>>c[p];
  18. v[c[p]]=1;
  19. d[c[p]]=1;
  20. }
  21. }
  22. void bfs()
  23. {
  24. int st=1;dr=k;
  25. while(st<=dr)
  26. {
  27. int nod=c[st++];
  28. for(int i=1;i<=n;i++)
  29. if(a[nod][i]==1 && !v[i])
  30. {
  31. v[i]=1;
  32. c[++dr]=d[nod]+1;
  33. if(zi<d[i])
  34. zi=d[i];
  35. }
  36. fout<<zi;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement