結果
問題 |
No.812 Change of Class
|
ユーザー |
|
提出日時 | 2020-04-26 19:15:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,609 bytes |
コンパイル時間 | 1,808 ms |
コンパイル使用メモリ | 174,236 KB |
実行使用メモリ | 9,428 KB |
最終ジャッジ日時 | 2024-11-17 18:49:48 |
合計ジャッジ時間 | 7,012 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 WA * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (int)n; ++i) #define FOR(i, a, b) for(int i = a; i < (int)b; ++i) #define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i) typedef long long ll; typedef long double ld; const int Inf = 1e9; const double EPS = 1e-9; const int MOD = 1e9 + 7; int check(int x) { int cnt = 0; while (x > 0) { x /= 2; cnt++; } return cnt; } int main() { cin.tie(nullptr); ios::sync_with_stdio(0); int n, m, q; cin >> n >> m; vector<int> g[n]; rep (i, m) { int s, t; cin >> s >> t; g[s - 1].push_back(t - 1); g[t - 1].push_back(s - 1); } cin >> q; rep (i, q) { int a; cin >> a; a--; if (g[a].size() == 0) { cout << 0 << " " << 0 << endl; continue; } int cnt = 0; int day = 0; vector<int> checked(n, Inf); queue<int> q; rep (j, g[a].size()) { q.push(g[a][j]); checked[g[a][j]] = 0; cnt++; } checked[a] = 0; while (!q.empty()) { int next = q.front(); q.pop(); rep (j, g[next].size()) { if (checked[g[next][j]] < checked[next] + 1) continue; checked[g[next][j]] = checked[next] + 1; q.push(g[next][j]); cnt++; } int tmp = check(checked[next]); day = max(day, tmp); } cout << cnt << " " << day << endl; } return 0; }