This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |