結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
shibh308
|
| 提出日時 | 2019-03-18 19:54:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,278 bytes |
| コンパイル時間 | 1,861 ms |
| コンパイル使用メモリ | 203,016 KB |
| 最終ジャッジ日時 | 2025-01-06 23:30:01 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 10 WA * 50 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n, m;
cin >> n >> m;
vector<int> x(m), y(m);
for(int i = 0; i < m; ++i){
cin >> x[i] >> y[i];
--x[i], --y[i];
}
int q;
cin >> q;
vector<int> a(q);
for(int i = 0; i < q; ++i){
cin >> a[i];
--a[i];
}
vector<vector<int>> edges(n);
for(int i = 0; i < m; ++i){
edges[x[i]].push_back(y[i]);
edges[y[i]].push_back(x[i]);
}
for(int i = 0; i < q; ++i){
int id = a[i];
vector<int> dist(n, 1e9);
queue<int> que;
dist[id] = 0;
que.push(id);
while(!que.empty()){
int from = que.front();
que.pop();
for(auto to : edges[from]){
if(dist[to] > dist[from] + 1){
dist[to] = dist[from] + 1;
que.push(to);
}
}
}
int cnt = 0, time = 0;
for(int i = 0; i < n; ++i)
if(i != id && dist[i] != 1e9){
++cnt;
time = max(time, dist[i] - 1);
}
cout << cnt << " " << time << endl;
}
}
shibh308