以下为正文:
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
const int MOD = 1e9 + 7;
struct Edge {
int u, v, weight;
bool operator<(const Edge &other) const {
return weight < other.weight;
}
};
struct UnionFind {
vector<int> parent;
UnionFind(int n) : parent(n) {
iota(parent.begin(), parent.end(), 0);
}
int find(int x) {
if (x != parent[x])
parent[x] = find(parent[x]);
return parent[x];
}
void unite(int x, int y) {
parent[find(x)] = find(y);
}
};
int main() {
int N, K;
cin >> N >> K;
vector<Edge> edges;
int edgeCount = (N - 1) * K + (K - 1) * N;
edges.reserve(edgeCount);
}
好像有点超时了
最后是46.72MB