CF - Design Tutorial Inverse the Problem

Author: Weiming Zhou


Official Analysis

Implementation

Time Complexity: O(N2logN)\mathcal{O}(N^2\log N) with Kruskal's MST or O(N2)\mathcal{O}(N^2) with N2N^2 Prims.

C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

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!