CSES - Finding a Centroid
Author: Dong Liu
Appears In
Time Complexity:
For more information about centroids and how to find/use them, see their module.
C++
#include <bits/stdc++.h>using namespace std;const int maxn = 2e5+5;int n; // number of nodesvector<int> g[maxn]; // graphint s[maxn]; // size of subtreevoid dfs_size(int cur, int par) {s[cur] = 1;
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!