// IO #include #include #include #include // algorithm #include #include #include // container #include #include #include #include #include #include #include #include #include // others #include #include #include #include #include // type alias using lint = long long; using ldouble = long double; template using greater_priority_queue = std::priority_queue, std::greater>; /* ----- class ----- */ template struct Edge { int from, to; Cost cost; Edge(int from = -1, int to = -1, Cost cost = 1) : from(from), to(to), cost(cost){}; bool operator<(const Edge& e) const { return this->cost < e.cost; } bool operator>(const Edge& e) const { return this->cost > e.cost; } }; template using Edges = std::vector>; template class Graph { public: int size; std::vector>> path; explicit Graph(int N = 0) : size(N), path(size) {} void span(int from, int to, Cost cost = 1) { path[from].push_back(Edge(from, to, cost)); } std::vector>& operator[](int v) { return path[v]; } }; /* ----- Output Functions for Debugging ----- */ template std::ostream& operator<<(std::ostream& os, std::vector v); template std::ostream& operator<<(std::ostream& os, std::set v); template std::ostream& operator<<(std::ostream& os, std::pair p); template std::ostream& operator<<(std::ostream& os, std::map v); template std::ostream& operator<<(std::ostream& os, std::stack s); template std::ostream& operator<<(std::ostream& os, std::queue q); template std::ostream& operator<<(std::ostream& os, std::priority_queue q); template std::ostream& operator<<(std::ostream& os, std::priority_queue, std::greater> q); template std::ostream& operator<<(std::ostream& os, Edge e); template std::ostream& operator<<(std::ostream& os, std::vector v) { os << "["; for (auto vv : v) os << vv << ","; return os << "]"; } template std::ostream& operator<<(std::ostream& os, std::set v) { os << "{"; for (auto vv : v) os << vv << ","; return os << "}"; } template std::ostream& operator<<(std::ostream& os, std::pair p) { return os << "(" << p.first << "," << p.second << ")"; } template std::ostream& operator<<(std::ostream& os, std::map v) { os << "{"; for (auto vv : v) os << vv << ","; return os << "}"; } template std::ostream& operator<<(std::ostream& os, std::stack s) { os << "["; while (!s.empty()) { os << s.top() << ","; s.pop(); } return os << "]"; } template std::ostream& operator<<(std::ostream& os, std::queue q) { os << "["; while (!q.empty()) { os << q.front() << ","; q.pop(); } return os << "]"; } template std::ostream& operator<<(std::ostream& os, std::priority_queue q) { os << "{"; while (!q.empty()) { os << q.top() << ","; q.pop(); } return os << "}"; } template std::ostream& operator<<(std::ostream& os, std::priority_queue, std::greater> q) { os << "{"; while (!q.empty()) { os << q.top() << ","; q.pop(); } return os << "}"; } template std::ostream& operator<<(std::ostream& os, Edge e) { return os << "(" << e.from << "->" << e.to << ":" << e.cost << ")"; } /* ----- Short Functions ----- */ template inline T sq(T a) { return a * a; } template inline T iceil(T n, T d) { return (n + d - 1) / d; } template T gcd(T a, T b) { while (b > 0) { a %= b; std::swap(a, b); } return a; } template T ipow(T b, U n) { T ret = 1; while (n > 0) { if (n & 1) ret *= b; n >>= 1; b *= b; } return ret; } // 0-indexed template inline T kthbit(T a, U k) { return (a >> k) & 1; } template inline T mask(T a, U k) { return a & ((1 << k) - 1); } template std::map compress(std::vector& v) { std::sort(v.begin(), v.end()); v.erase(std::unique(v.begin(), v.end()), v.end()); std::map rev; for (int i = 0; i < v.size(); ++i) rev[v[i]] = i; return rev; } template T Vec(T v) { return v; } template auto Vec(size_t l, Ts... ts) { return std::vector(ts...))>(l, Vec(ts...)); } /* ----- Constants ----- */ const int INF = std::numeric_limits::max() / 3; // const ll INF = std::numeric_limits::max() / 3; // const ld PI = acos(-1); // const ld EPS = 1e-10; // std::mt19937 mt(int(std::time(nullptr))); class UnionFind { private: std::vector par, num; int find(int v) { return (par[v] == v) ? v : (par[v] = find(par[v])); } public: explicit UnionFind(int N) : par(N), num(N, 1) { std::iota(par.begin(), par.end(), 0); } void unite(int u, int v) { u = find(u), v = find(v); if (u == v) return; if (num[u] < num[v]) std::swap(u, v); num[u] += num[v]; par[v] = u; } bool same(int u, int v) { return find(u) == find(v); } bool ispar(int v) { return v == find(v); } int size(int v) { return num[find(v)]; } }; template std::vector dijkstra(Graph& graph, std::vector ss) { std::vector dist(graph.size, INF); std::priority_queue, std::vector>, std::greater>> que; for (auto s : ss) { dist[s] = 0; que.emplace(0, s); } while (!que.empty()) { int v; Cost d; std::tie(d, v) = que.top(); que.pop(); if (d > dist[v]) continue; for (auto e : graph[v]) { if (dist[e.to] <= dist[v] + e.cost) continue; dist[e.to] = dist[v] + e.cost; que.emplace(dist[e.to], e.to); } } return dist; } int main() { int N, M; std::cin >> N >> M; Graph<> graph(N); UnionFind uf(N); for (int i = 0; i < M; ++i) { int p, q; std::cin >> p >> q; --p, --q; graph.span(p, q); graph.span(q, p); uf.unite(p, q); } int Q; std::cin >> Q; for (int q = 0; q < Q; ++q) { int a; std::cin >> a; --a; std::cout << uf.size(a) - 1 << " "; auto dist = dijkstra<>(graph, {a}); // std::cerr << dist << std::endl; int max = 1; for (auto d : dist) { if (0 < d && d < INF) max = std::max(max, d); } int day; for (day = 0; day < 30; ++day) { if ((1 << day) >= max) break; } std::cout << day << std::endl; } return 0; }