Submission #17963

#TimeUsernameProblemLanguageResultExecution timeMemory
17963AdilkhanShymbulak (IZhO14_shymbulak)C++98
50 / 100
706 ms205288 KiB
#include <bits/stdc++.h> #define pb push_back #define endl "\n" #define mp make_pair #define fi first #define se second #define all(x) x.begin(), x.end() #define fname "" #define sz(x) (int)(x.size()) typedef long long ll; using namespace std; const ll N = 5020; const ll INF = (ll)(1e9); const ll mod = (ll)(1e9) + 7; const double eps = 1e-9; int d[N][N][2], n, m, mx, sum; vector <int> v[N]; queue <int> q; void fmbfs(int s) { for (int i = 1; i <= n; ++i) d[s][i][1] = 0, d[s][i][0] = -1; q.push(s); d[s][s][0] = 0; d[s][s][1] = 1; while (!q.empty()) { int x = q.front(); q.pop(); for (int j = 0; j < sz(v[x]); ++j) { int to = v[x][j]; if (d[s][to][0] == -1) { d[s][to][0] = d[s][x][0] + 1; d[s][to][1] += d[s][x][1]; q.push(to); continue; } if (d[s][to][0] == d[s][x][0] + 1) { d[s][to][1] += d[s][x][1]; } } } for (int i = 1; i <= n; ++i) { mx = max(mx, d[s][i][0]); } } int main () { //freopen(fname".in", "r", stdin); //freopen(fname".out", "w", stdout); scanf("%lld", &n); for (int i = 1; i <= n; ++i) { ll x, y; scanf("%lld%lld", &x, &y); v[x].pb(y); v[y].pb(x); } for (int i = 1; i <= n; ++i) { fmbfs(i); } for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { if (d[i][j][0] == mx) { sum += d[i][j][1]; } } } printf("%lld", sum); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...