結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-12 22:19:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,079 bytes |
| コンパイル時間 | 675 ms |
| コンパイル使用メモリ | 68,540 KB |
| 実行使用メモリ | 9,020 KB |
| 最終ジャッジ日時 | 2024-06-12 18:59:24 |
| 合計ジャッジ時間 | 5,060 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 9 WA * 51 |
ソースコード
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
int main() {
int n, m; scanf("%d%d", &n, &m);
std::vector<std::vector<int>> g(n);
for(int i = 0; i < m; i++) {
int a, b; scanf("%d%d", &a, &b);
g[a - 1].push_back(b - 1);
g[b - 1].push_back(a - 1);
}
int q; scanf("%d", &q);
while(q--) {
int a; scanf("%d", &a);
std::vector<int> min_cost(n, 1 << 30);
std::queue<int> qu; qu.push(a - 1); min_cost[a - 1] = 0;
while(!qu.empty()) {
auto p = qu.front(); qu.pop();
for(auto e: g[p]) {
if(min_cost[p] + 1 >= min_cost[e]) continue;
min_cost[e] = min_cost[p] + 1;
qu.push(e);
}
}
int count = 0, ans = 0;
for(int i = 0; i < n; i++) {
if(min_cost[i] == 1 << 30) continue;
count++;
ans = std::max(ans, min_cost[i]);
}
printf("%d %d\n", count - 1, (ans + 1) / 2);
}
return 0;
}