#include #include #include #include using namespace std; class UnionFind{ private: vector p,s; public: UnionFind(){} UnionFind(int N){ p = s = vector(N+1,0); for(int i=1;i<=N;i++){ p[i] = i; s[i] = 1; } } int find(int x){ if(p[x]==x) return x; else return p[x] = find(p[x]); } void unite(int x,int y){ x = find(x); y = find(y); if(x==y) return; if(s[x]>s[y]){ p[y] = x; s[x] += s[y]; }else{ p[x] = y; s[y] += s[x]; } } bool is_same_set(int x,int y) {return find(x)==find(y);} int size(int x) {return s[find(x)];} }; int N,M,p,q,Q,a; int visited[100010] = {}; vector> v(100010); int bfs(int n){ for(int i=1;i<=N;i++) visited[i] = -1; queue Q; visited[n] = 0; Q.push(n); int res = 0; while(!Q.empty()){ int a = Q.front(); Q.pop(); for(auto x:v[a]){ if(visited[x]==-1){ visited[x] = visited[a]+1; Q.push(x); res = max(res,visited[x]); } } } return res; } int main(){ cin >> N >> M; UnionFind uf(N); for(int i=0;i> p >> q; v[p].push_back(q); v[q].push_back(p); uf.unite(p,q); } cin >> Q; for(int i=0;i> a; cout << uf.size(a)-1 << " "; if(uf.size(a)-1==1) cout << 0 << endl; else cout << (bfs(a)+1)/2 << endl; } }