Codeforces - Design Tutorial Inverse the Problem

Author: Weiming Zhou


Official Analysis

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++

// https://codeforces.com/contest/472/submission/117118910
#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)

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!