# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
993474 | doducanh | Hard route (IZhO17_road) | C++14 | 578 ms | 179028 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;
using ll = long long;
int main() {
int n;
cin >> n;
vector<vector<int>> adj(n);
for (int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
adj[--x].push_back(--y);
adj[y].push_back(x);
}
vector<int> max_length(n);
vector<int> path_count(n);
/**
* Calculates the longest path from vertex u,
* and the number of such paths.
*/
function<void(int, int)> dfs = [&](int u, int p) {
max_length[u] = 0;
path_count[u] = 1;
for (int v : adj[u])
if (v != p) {
dfs(v, u);
if (max_length[u] < max_length[v] + 1) {
max_length[u] = max_length[v] + 1;
path_count[u] = path_count[v];
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |