Submission #499123

#TimeUsernameProblemLanguageResultExecution timeMemory
499123boykutShymbulak (IZhO14_shymbulak)C++14
50 / 100
1563 ms7108 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...