結果
問題 |
No.812 Change of Class
|
ユーザー |
|
提出日時 | 2025-09-28 07:26:43 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 169 ms / 4,000 ms |
コード長 | 1,157 bytes |
コンパイル時間 | 3,316 ms |
コンパイル使用メモリ | 284,344 KB |
実行使用メモリ | 9,852 KB |
最終ジャッジ日時 | 2025-09-28 07:26:53 |
合計ジャッジ時間 | 9,934 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 60 |
ソースコード
// #pragma GCC optimize ("Ofast") // #pragma GCC optimize ("unroll-loops") // #pragma GCC target ("avx,avx2,fma") #include <bits/stdc++.h> using std::cin, std::cout, std::cerr; using ll = long long; int main() { std::ios::sync_with_stdio(false); int n, m; cin >> n >> m; std::vector<std::vector<int>> e(n + 1); for(int i = 1; i <= m; i ++) { int u, v; cin >> u >> v; e[u].push_back(v); e[v].push_back(u); } int q; cin >> q; while(q --) { int s; cin >> s; std::vector<int> d(n + 1), vis(n + 1); vis[s] = 1; std::queue<int> q; q.push(s); while(!q.empty()) { int x = q.front(); q.pop(); for(int i : e[x]) if(!vis[i]) { vis[i] = 1; d[i] = d[x] + 1; q.push(i); } } int cnt = 0, max = 1; for(int i = 1; i <= n; i ++) if(vis[i] && d[i] >= 1) { cnt ++; max = std::max(max, d[i]); } // cout << cnt << ' ' << max << '\n'; cout << cnt << ' ' << int(std::ceil(std::log2(max))) << '\n'; } }