daily pastebin goal
53%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("dmax.in");
  6. ofstream fout("dmax.out");
  7.  
  8. int n, m, x, y,q[101],d[1001],a[1001][1001],nod,viz[101];
  9.  
  10. void Citire()
  11. {
  12.     fin >> n >> m;
  13.     while(fin >> x >> y)
  14.     {
  15.         a[x][y] =  a[y][x] = 1;
  16.     }
  17. }
  18.  
  19. void BFS(int S)
  20. { int i;
  21.    int pr,ul;
  22.    pr = ul = 1;
  23.    viz[S] = 0;
  24.    q[1] = S;
  25.    d[S] = 0;
  26.    while(pr <= ul)
  27.    {
  28.        nod=q[pr];
  29.        pr++;
  30.        for( i = 1;i <= n;i++)
  31.         if(viz[i] == 0 && a[nod][i] == 1)
  32.        {
  33.            viz[i] = 1;
  34.            q[++ul] = i;
  35.            d[i] = 1 +d[nod];
  36.        }
  37.    }
  38. }
  39.  
  40. int main()
  41. { int maxim, i;
  42.    Citire();
  43.    BFS(1);
  44.    maxim=0;
  45.    for(i = 1;i <= n; i++)
  46.     if(d[i] > maxim) maxim =d[i];
  47.     fout << maxim;
  48.    fin.close();
  49.    fout.close();
  50.     return 0;
  51. }
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