0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-28 14:11:58 +00:00

[USACO09OPEN]Hide and Seek S

R57850314
This commit is contained in:
Baoshuo Ren 2021-09-11 20:36:15 +08:00 committed by Baoshuo Ren
parent 160dbed5d3
commit 90b0f86e1d
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,44 @@
#include <bits/stdc++.h>
using namespace std;
int n, m, u, v, dist[200005], ans1, ans2, ans3;
vector<int> g[200005];
void spfa() {
memset(dist, 0x3f, sizeof(dist));
dist[1] = 0;
queue<int> q;
q.push(1);
while (!q.empty()) {
auto t = q.front();
q.pop();
for (auto i : g[t]) {
if (dist[i] > dist[t] + 1) {
dist[i] = dist[t] + 1;
q.push(i);
}
}
}
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
spfa();
for (int i = 1; i <= n; i++) {
if (ans2 < dist[i]) {
ans2 = dist[i];
ans1 = i;
}
}
for (int i = 1; i <= n; i++) {
ans3 += dist[i] == ans2;
}
cout << ans1 << ' ' << ans2 << ' ' << ans3 << endl;
return 0;
}