Some cups are on the desktop, and some of these cups have small balls under them. You can ask how many small balls are parity under the I to J cup, and how much is spent to know the existence of the small ball under the cup.
Train of Thought: Let's look at this question to see how to think about the parity of Chubby, which is actually the same, but this question uses the conclusion of that question. If you have not done so, you can do the question first, and use and maintain the query set. This question is bare, but it is only a process of generating the minimum tree.
Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX 2010using namespace std;struct Edge{int x,y,length;Edge(int _ = 0,int __ = 0,int ___ = 0):x(_),y(__),length(___) {}bool operator <(const Edge &a)const {return length < a.length;}}edge[MAX * MAX];int cnt,total;int father[MAX];int Find(int x){if(father[x] == x)return x;return father[x] = Find(father[x]);}int main(){cin >> cnt;for(int i = 1; i <= cnt + 1; ++i)father[i] = i;for(int i = 1; i <= cnt; ++i)for(int z,j = i; j <= cnt; ++j) {scanf("%d",&z);edge[++total] = Edge(i,j + 1,z);}sort(edge + 1,edge + total + 1);long long ans = 0,t = 0;for(int i = 1; i <= total; ++i) {int fx = Find(edge[i].x);int fy = Find(edge[i].y);if(fx != fy) {father[fy] = fx;ans += edge[i].length;if(++t == cnt)break;}}cout << ans << endl;return 0;}
Bzoj 3714 PA 2014 kuglarz Minimum Spanning Tree