Submission #682645

#TimeUsernameProblemLanguageResultExecution timeMemory
682645opPOHard route (IZhO17_road)C++17
19 / 100
2089 ms98776 KiB
#pragma GCC optimize("O3,unroll-loops") #include <bits/stdc++.h> using namespace std; #define f first #define s second #define pb push_back #define ld long double #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define vec vector using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count()); const ld eps = 1e-6; const int mod = 998244353; const int oo = 2e9; const ll OO = 2e18; const int N = 5000 + 10; int n, dist[N][N], ans, cnt; vec<int> g[N], path; bool used[N]; void dfs(int v) { used[v] = true; path.pb(v); if (sz(path) > 1 && sz(g[path[0]]) == 1 && sz(g[path.back()]) == 1) { int H = 0; for (int u = 1; u <= n; u++) { int mn = oo; for (int &vert : path) mn = min(mn, dist[u][vert]); H = max(H, mn); } if ((sz(path) - 1) * H > ans) { ans = (sz(path) - 1) * H; cnt = 1; } else if ((sz(path) - 1) * H == ans) cnt++; } for (int &to : g[v]) { if (used[to]) continue; dfs(to); } used[v] = false; path.pop_back(); } void solve() { cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } for (int v = 1; v <= n; v++) { queue<int> q; q.push(v); fill(dist[v], dist[v] + N, oo); dist[v][v] = 0; while (!q.empty()) { int u = q.front(); q.pop(); for (int &to : g[u]) { if (dist[v][u] + 1 < dist[v][to]) { dist[v][to] = dist[v][u] + 1; q.push(to); } } } } for (int v = 1; v <= n; v++) dfs(v); cnt /= 2; cout << ans << " " << cnt; } int32_t main() { // freopen("bomb.in", "r", stdin); // freopen("bomb.out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...