結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
algon_320
|
| 提出日時 | 2019-04-12 22:29:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 162 ms / 4,000 ms |
| コード長 | 1,400 bytes |
| コンパイル時間 | 1,715 ms |
| コンパイル使用メモリ | 177,340 KB |
| 実行使用メモリ | 10,460 KB |
| 最終ジャッジ日時 | 2024-06-12 19:13:15 |
| 合計ジャッジ時間 | 6,536 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 60 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
template <class T>
bool chmax(T &a, const T& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
constexpr int INF = 1e9;
signed main() {
int N, M;
cin >> N >> M;
vector<vector<int>> g(N);
rep(i, 0, M) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].push_back(b);
g[b].push_back(a);
}
int Q;
cin >> Q;
rep(i, 0, Q) {
int A;
cin >> A;
A--;
vector<int> dist(N, INF);
queue<int> q;
q.push(A);
dist[A] = 0;
int sum = 0;
int mx = 0;
while (q.size()) {
int v = q.front(); q.pop();
for (int w : g[v]) {
if (dist[w] > dist[v] + 1) {
dist[w] = dist[v] + 1;
chmax(mx, dist[w]);
q.push(w);
sum++;
}
}
}
int cnt = 0;
if (mx > 0) {
mx--;
while (mx) {
mx >>= 1;
cnt++;
}
}
cout << sum << " " << cnt << endl;
}
}
algon_320