SHARE
TWEET

Untitled

a guest Feb 26th, 2020 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  37.     }
  38.     fout<<zi;
  39. }
  40. int main()
  41. {
  42.     citire();
  43.     bfs();
  44.     return 0;
  45.  
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top