#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;
}
}
cout << cntans / 2 << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
4 ms |
332 KB |
Output is correct |
15 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
360 KB |
Output is correct |
2 |
Correct |
5 ms |
332 KB |
Output is correct |
3 |
Correct |
14 ms |
332 KB |
Output is correct |
4 |
Correct |
18 ms |
376 KB |
Output is correct |
5 |
Correct |
376 ms |
632 KB |
Output is correct |
6 |
Correct |
195 ms |
676 KB |
Output is correct |
7 |
Correct |
429 ms |
644 KB |
Output is correct |
8 |
Correct |
352 ms |
652 KB |
Output is correct |
9 |
Correct |
390 ms |
644 KB |
Output is correct |
10 |
Correct |
507 ms |
644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1563 ms |
7108 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |