#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 == 2 || cntans == 4);
cout << cntans / 2 << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1580 ms |
5948 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |