MST:Bad Cowtractors(POJ 2377)】的更多相关文章

坏的牛圈建筑 题目大意:就是现在农夫又要牛修建牛栏了,但是农夫想不给钱,于是牛就想设计一个最大的花费的牛圈给他,牛圈的修理费用主要是用在连接牛圈上 这一题很简单了,就是找最大生成树,把Kruskal算法改一下符号就好了,把边从大到小排列,然后最后再判断是否联通(只要找到他们的根节点是否相同就可以了!) #include <iostream> #include <algorithm> #include <functional> #define MAX_N 1005 #de…
题目连接 http://poj.org/problem?id=2377 Bad Cowtractors Description Bessie has been hired to build a cheap internet network among Farmer John's N (2 <= N <= 1,000) barns that are conveniently numbered 1..N. FJ has already done some surveying, and found…
http://poj.org/problem?id=2377 bessie要为FJ的N个农场联网,给出M条联通的线路,每条线路需要花费C,因为意识到FJ不想付钱,所以bsssie想把工作做的很糟糕,她想要花费越多越好,并且任意两个农场都需要连通,并且不能存在环.后面两个条件保证最后的连通图是一棵树. 输出最小花费,如果没办法连通所有节点输出-1. 最大生成树问题,按边的权值从大道小排序即可,kruskal算法可以处理重边的情况,但是在处理的时候,不能仅仅因为两个节点在同一个连通子图就判断图不合法…
Bad Cowtractors Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 1   Accepted Submission(s) : 1 Problem Description Bessie has been hired to build a cheap internet network among Farmer John's N (…
Bad Cowtractors Bessie has been hired to build a cheap internet network among Farmer John's N (2 <= N <= 1,000) barns that are conveniently numbered 1..N. FJ has already done some surveying, and found M (1 <= M <= 20,000) possible connection r…
Description Bessie has been hired to build a cheap internet network among Farmer John's N (2 <= N <= 1,000) barns that are conveniently numbered 1..N. FJ has already done some surveying, and found M (1 <= M <= 20,000) possible connection route…
题意:给出一个图,求出其中的最大生成树= =如果无法产生树,输出-1. 思路:将边权降序再Kruskal,再检查一下是否只有一棵树即可,即根节点只有一个 #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; int N, M; // 节点,边的数量 struct edge { int from, to, dist;…
链接:传送门 题意:给 n 个点 , m 个关系,求这些关系的最大生成树,如果无法形成树,则输出 -1 思路:输入时将边权转化为负值就可以将此问题转化为最小生成树的问题了 /************************************************************************* > File Name: poj2377.cpp > Author: WArobot > Blog: http://www.cnblogs.com/WArobot/ &g…
#include<stdio.h> #define MAXN 1005 #include<iostream> #include<algorithm> #define inf 10000000 using namespace std; int _m[MAXN][MAXN]; int low_cost[MAXN]; int pre[MAXN]; unsigned prime(int n); int DFS(int i,int sum,int p); bool mark[MA…
题意:建光纤的时候,拉一条最长的线 思路:最大生成树 将图的n个顶点看成n个孤立的连通分支,并将所有的边按权从大到小排 边权递减的顺序,如果加入边的两个端点不在同一个根节点的话加入,并且要将其连通,否则放弃 最后剩下一个连通支 解决问题的代码: #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<…