結果
問題 |
No.812 Change of Class
|
ユーザー |
![]() |
提出日時 | 2019-03-18 20:02:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,401 bytes |
コンパイル時間 | 1,840 ms |
コンパイル使用メモリ | 202,340 KB |
最終ジャッジ日時 | 2025-01-06 23:30:15 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 WA * 48 |
ソースコード
#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]); } int ans_time; if(time <= 1) ans_time = 0; else ans_time = (time + 1) / 2; cout << cnt << " " << ans_time << endl; } }