# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
299507 | shivensinha4 | Putovanje (COCI20_putovanje) | C++17 | 211 ms | 28664 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.
/*
COCI 2020 Putovanje
- Essentially want to find the number of times we traverse each edge
- We use the fact that A->B = A->LCA(A, B)->B
- A path A->B where B is an ancestor of A passes through the "parent"
edge of C iff B is an ancestor of C and C is an ancestor of A
- This means we can mark A with 1 and B with -1
- So the subtree sum is the number of paths passing through an edge!
- DFS to get DFS order and use a Fenwick tree to do stuff
- Complexity: O(N log N)
*/
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
int n;
vector<int> graph[200001];
ll bit[200001];
int tin[200001], tout[200001], timer = 0;
int anc[200001][20];
void dfs(int node = 1, int parent = 0) {
anc[node][0] = parent;
FOR(i, 1, 20) anc[node][i] = anc[anc[node][i - 1]][i - 1];
tin[node] = ++timer;
for (int i : graph[node]) if (i != parent) dfs(i, node);
tout[node] = timer;
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |