#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
srand(time(NULL));
int n;
cin >> n;
vector<int> g[n];
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
x--; y--;
g[x].push_back(y);
g[y].push_back(x);
}
int ansdist = 0, cntans = 0;
for (int i = 0; i < n; i++) {
vector<int> d(n, INT_MAX);
queue<int> q;
q.push(i);
d[i] = 0;
int maxdist = 0, cntdist = 0;
while (!q.empty()) {
int v = q.front(); q.pop();
for (auto u : g[v]) {
if (d[u] >= d[v] + 1) {
d[u] = d[v] + 1;
q.push(u);
if (d[u] == maxdist)
cntdist++;
if (d[u] > maxdist) {
maxdist = d[u];
cntdist = 1;
}
}
}
}
if (maxdist == ansdist)
cntans += cntdist;
if (maxdist > ansdist) {
ansdist = maxdist;
cntans = cntdist;
}
}
assert(cntans == 8 || cntans == 4);
cout << cntans / 2 << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1587 ms |
5940 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |