Table of Contents
Edit on GithubDMOJ - Bob Equilibrium
Author: Benjamin Qi
Time Complexity:
Using centroid decomposition, we can
- Update the value at some vertex in time
- Query the sum of the values of all vertices that are distance exactly away from some vertex in time.
You can check the second approach for USACO At Large for an explanation of how to do this.
What we need for this problem is slightly different; first we need to process some number of updates of the following form:
- Add 1 to the values of all vertices at most away from some vertex .
And then output the values at all vertices at the end. We can use prefix sums for this.
(Note: quite close to TL ...)
1#include <bits/stdc++.h>2using namespace std;34using ll = long long;5using ld = long double;6using db = double;7using str = string; // yay python!89using pi = pair<int,int>;10using pl = pair<ll,ll>;
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!