#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; void solve() { int N,M; cin >> N >> M; vector> G(N); for(int i = 0;i < M;i++) { int u,v; cin >> u >> v; u--; v--; G[u].push_back(v); G[v].push_back(u); } int Q; cin >> Q; for(;Q--;) { int a; cin >> a; a--; vector dp(N,-1); dp[a] = 0; queue q; q.push(a); while(!q.empty()) { int u = q.front(); q.pop(); for(int v:G[u]) if(dp[v] < 0) { dp[v] = dp[u] + 1; q.push(v); } } int cnt = 0,mx = 0; for(int i = 0;i < N;i++) { if(dp[i] > 0) cnt++; mx = max(mx,dp[i]); } //0 -> 0 //1 -> 0 //2 -> 1 //3 -> 2 //4 -> 2 //5 -> cout << cnt << " "; if(mx <= 1) cout << 0; else cout << (mx + 1) / 2; cout << "\n"; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt = 1; /* cin >> tt; */ while(tt--) solve(); }