Bzoj 3714 PA 2014 kuglarz Minimum Spanning Tree

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.