結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-12 22:20:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,083 bytes |
| コンパイル時間 | 624 ms |
| コンパイル使用メモリ | 67,280 KB |
| 実行使用メモリ | 9,024 KB |
| 最終ジャッジ日時 | 2024-06-12 19:01:54 |
| 合計ジャッジ時間 | 4,620 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 11 WA * 49 |
ソースコード
#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] - 1);
}
printf("%d %d\n", count - 1, (ans + 1) / 2);
}
return 0;
}