結果
問題 |
No.812 Change of Class
|
ユーザー |
|
提出日時 | 2020-09-02 20:55:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 168 ms / 4,000 ms |
コード長 | 1,149 bytes |
コンパイル時間 | 2,502 ms |
コンパイル使用メモリ | 198,808 KB |
最終ジャッジ日時 | 2025-01-14 03:47:54 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 60 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++) #define ALL(x) (x).begin(), (x).end() const double PI = acos(-1); const int INF = 1<<28; int n, m; vector<int> edges[100000]; int dist[100000]; int ceil_log(int x) { int r = log2(x); if (1<<r < x) ++r; return r; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; REP (i, m) { int p, q; cin >> p >> q; --p, --q; edges[p].push_back(q); edges[q].push_back(p); } int q; cin >> q; while (q--) { int v; cin >> v; --v; fill(dist, dist + n, INF); queue<int> que; que.push(v); dist[v] = 0; int c = 0; int d = 0; while (!que.empty()) { int u = que.front(); que.pop(); ++c; d = max(d, dist[u]); for (int w: edges[u]) { if (dist[w] == INF) { dist[w] = dist[u] + 1; que.push(w); } } } if (!--c) cout << 0 << " " << 0 << endl; else cout << c << " " << ceil_log(d) << endl; } return 0; }