//Suleyman Atayew
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#define N 5010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define inf 1000000007
#define pii pair <ll, ll>
using namespace std;
ll n;
ll a, b;
ll v[N][N];
vector <ll> E[N];
int main()
{
cin >> n;
for(ll i = 1; i <= n; i++) {
cin >> a >> b;
E[a].pb(b);
E[b].pb(a);
}
for(ll i = 1; i <= n; i++)
for(ll h = 1; h <= n; h++)
v[i][h] = 1e9;
for(ll i = 1; i <= n; i++) {
queue <ll> Q;
Q.push(i);
v[i][i] = 0;
while(!Q.empty()) {
ll x = Q.front();
Q.pop();
for(auto h: E[x])
if(v[i][h] == 1e9) {
v[i][h] = v[i][x] + 1;
Q.push(h);
}
}
}
ll mx = 0;
for(ll i = 1; i <= n; i++)
for(ll h = 1; h <= n; h++)
mx = max(mx, v[i][h]);
vector <pii> A;
for(ll i = 1; i <= n; i++)
for(ll h = i; h <= n; h++)
if(mx == v[i][h])
A.pb({i, h});
ll ans = 0;
for(auto i: A) {
ll a = i.ff, b = i.ss;
queue <ll> Q;
Q.push(b);
ll arr[N];
ll vis[N];
memset(arr, 0, sizeof(arr));
memset(vis, 0, sizeof(vis));
while(!Q.empty()) {
ll x = Q.front();
Q.pop();
for(auto i: E[x])
if(v[a][i] == v[a][x]-1 && vis[i] == 0)
arr[v[a][i]]++, Q.push(i), vis[i] = 1;
}
ll sum = 1;
for(ll i = 0; i < mx; i++) sum *= arr[i];
ans += sum;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
3 ms |
632 KB |
Output is correct |
6 |
Incorrect |
3 ms |
632 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
7416 KB |
Output is correct |
2 |
Execution timed out |
1563 ms |
17076 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
872 ms |
262144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |