# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90861 | daniel_02 | Shymbulak (IZhO14_shymbulak) | C++17 | 1569 ms | 11476 KiB |
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>
#define fr first
#define pb push_back
#define sc second
#define ll long long
using namespace std;
const int N = 2e5 + 7;
const int inf = 1e6 + 7;
vector<int>g[N];
int d[N];
int cn[N];
queue<pair<int, int>>q;
void mems(){
for (int i = 0; i < N; i++)
d[i] = inf;
queue<pair<int, int>>empty;
swap(q, empty);
}
void dance(int a)
{
mems();
q.push({a, 0});
d[a] = 0;
while (!q.empty())
{
int v = q.front().fr, cs = q.front().sc;
q.pop();
if (cs > d[v])continue;
for (int i = 0; i < g[v].size(); i++)
{
int to = g[v][i];
if (cs + 1 <= d[to])
{
d[to] = cs + 1;
cn[d[to]]++;
q.push({to, d[to]});
}
}
}
}
main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
int a, b;
scanf("%d%d", &a, &b);
g[a].pb(b);
g[b].pb(a);
}
int mx = 0;
for (int i = 1; i <= n; i++)
{
dance(i);
for (int j = 1; j <= n; j++)
{
if (i == j)continue;
mx = max(mx, d[j]);
}
}
cout << cn[mx] / 2 << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |