# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
404613 | rama_pang | Hard route (IZhO17_road) | C++17 | 844 ms | 101652 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
vector<vector<int>> adj(N);
for (int i = 1; i < N; i++) {
int u, v;
cin >> u >> v;
u--, v--;
adj[u].emplace_back(v);
adj[v].emplace_back(u);
}
// Let's fix a node u, and consider the 3 maximum distances
// from u (where each is from different children). WLOG,
// a <= b <= c. Then, the optimal hardness is c * (a + b).
//
// For (a, b, c) and node u, note that we can canonize the
// route (a, b). For a fixed route (a, b), there might be
// a lot of count(max(c)). However, if there is more than
// 1 occurrence of length at least c, then at node u it
// wouldn't be (a, b, c); instead it would be (a, c + x, c),
// (we extend b to instead use the c-route since it's longer),
// so it would be a different route. This way, c is unique
// for a route (a, b) and only counted once.
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |