# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
682645 |
2023-01-16T16:32:03 Z |
opPO |
Hard route (IZhO17_road) |
C++17 |
|
2000 ms |
98776 KB |
#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 time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
2388 KB |
Output is correct |
8 |
Correct |
2 ms |
2388 KB |
Output is correct |
9 |
Correct |
2 ms |
2388 KB |
Output is correct |
10 |
Correct |
2 ms |
2388 KB |
Output is correct |
11 |
Correct |
6 ms |
2428 KB |
Output is correct |
12 |
Correct |
6 ms |
2388 KB |
Output is correct |
13 |
Correct |
7 ms |
2376 KB |
Output is correct |
14 |
Correct |
7 ms |
2388 KB |
Output is correct |
15 |
Correct |
2 ms |
2388 KB |
Output is correct |
16 |
Correct |
2 ms |
2388 KB |
Output is correct |
17 |
Correct |
2 ms |
2388 KB |
Output is correct |
18 |
Correct |
2 ms |
2380 KB |
Output is correct |
19 |
Correct |
2 ms |
2376 KB |
Output is correct |
20 |
Correct |
1 ms |
2388 KB |
Output is correct |
21 |
Correct |
1 ms |
2260 KB |
Output is correct |
22 |
Correct |
2 ms |
2260 KB |
Output is correct |
23 |
Correct |
2 ms |
2248 KB |
Output is correct |
24 |
Correct |
6 ms |
2428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
2388 KB |
Output is correct |
8 |
Correct |
2 ms |
2388 KB |
Output is correct |
9 |
Correct |
2 ms |
2388 KB |
Output is correct |
10 |
Correct |
2 ms |
2388 KB |
Output is correct |
11 |
Correct |
6 ms |
2428 KB |
Output is correct |
12 |
Correct |
6 ms |
2388 KB |
Output is correct |
13 |
Correct |
7 ms |
2376 KB |
Output is correct |
14 |
Correct |
7 ms |
2388 KB |
Output is correct |
15 |
Correct |
2 ms |
2388 KB |
Output is correct |
16 |
Correct |
2 ms |
2388 KB |
Output is correct |
17 |
Correct |
2 ms |
2388 KB |
Output is correct |
18 |
Correct |
2 ms |
2380 KB |
Output is correct |
19 |
Correct |
2 ms |
2376 KB |
Output is correct |
20 |
Correct |
1 ms |
2388 KB |
Output is correct |
21 |
Correct |
1 ms |
2260 KB |
Output is correct |
22 |
Correct |
2 ms |
2260 KB |
Output is correct |
23 |
Correct |
2 ms |
2248 KB |
Output is correct |
24 |
Correct |
6 ms |
2428 KB |
Output is correct |
25 |
Execution timed out |
2089 ms |
98776 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
2388 KB |
Output is correct |
8 |
Correct |
2 ms |
2388 KB |
Output is correct |
9 |
Correct |
2 ms |
2388 KB |
Output is correct |
10 |
Correct |
2 ms |
2388 KB |
Output is correct |
11 |
Correct |
6 ms |
2428 KB |
Output is correct |
12 |
Correct |
6 ms |
2388 KB |
Output is correct |
13 |
Correct |
7 ms |
2376 KB |
Output is correct |
14 |
Correct |
7 ms |
2388 KB |
Output is correct |
15 |
Correct |
2 ms |
2388 KB |
Output is correct |
16 |
Correct |
2 ms |
2388 KB |
Output is correct |
17 |
Correct |
2 ms |
2388 KB |
Output is correct |
18 |
Correct |
2 ms |
2380 KB |
Output is correct |
19 |
Correct |
2 ms |
2376 KB |
Output is correct |
20 |
Correct |
1 ms |
2388 KB |
Output is correct |
21 |
Correct |
1 ms |
2260 KB |
Output is correct |
22 |
Correct |
2 ms |
2260 KB |
Output is correct |
23 |
Correct |
2 ms |
2248 KB |
Output is correct |
24 |
Correct |
6 ms |
2428 KB |
Output is correct |
25 |
Execution timed out |
2089 ms |
98776 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |