Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define nmax 101
- using namespace std;
- ifstream fin("dmax.in");
- ofstream fout("dmax.out");
- int n,m,d[nmax],viz[nmax];
- vector<int>h[nmax];
- queue<int>c;
- void Citire()
- {
- int i,x,y;
- fin>>n>>m;
- for(i=1;i<=m;i++)
- {
- fin>>x>>y;
- h[x].push_back(y);
- h[y].push_back(x);
- }
- }
- void BFS()
- {
- int i,x,p;
- p=1;
- viz[p]=1;
- c.push(p);
- while(!c.empty())
- {
- x=c.front();
- c.pop();
- for(i=0;i<h[x].size();i++)
- if(!viz[h[x][i]])
- {
- viz[h[x][i]]=1;
- c.push(h[x][i]);
- d[h[x][i]]=d[x]+1;
- }
- }
- }
- int main()
- {
- int i,maxim=0,poz;
- Citire();
- BFS();
- for(i=1;i<=n;i++)
- if(maxim<d[i])
- {
- maxim=d[i];
- poz=i;
- }
- fout<<poz<<" ";
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment