Problem E
行对应村庄间道路的成本及修建状态,每行给4个正整数,分别是两个村庄的编号(从1编号到N),此两村庄间道路的成本,以及修建状态:1表示已建,0表示未建。
当N为0时输入结束。
3 2 0 2 3 4 0 3 1 2 1 0 1 3 2 0 2 3 4 1 3 1 2 1 0 1 3 2 1 2 3 4 1
0
using namespace std;
#define N 110
struct node
{
int
i,j,w,f;//从i到j需要w,f表示是否连通
};
node fr[N*N];
int bin[N];
bool comp(node a,node b)
{
return
a.w
}
int find1(int x)
{
int
r=x;
while(bin[r]!=r)
r=bin[r];
return
r;
}
int kruskal(int n,int m)
{
sort(fr,fr+m,comp);
int
s=0;
for(int
i=0;i
{
int fx=find1(fr[i].i);
int fy=find1(fr[i].j);
if(fx!=fy)
{
//cout<<"p="<<fr[i].f<<endl;
bin[fx]=fy;
//cout<<bin[fy]<<" "<<fy<<endl;
s+=fr[i].w;
}
}
return
s;
}
int main()
{
//freopen("in.txt", "r", stdin);
int
n,t;
while(scanf("%d",&n)!=EOF&&n)
{
t=n*(n-1)/2;
for(int i=0;i<=n;i++)
bin[i]=i;
for(int i=0;i
{
scanf("%d%d%d%d",&fr[i].i,&fr[i].j,&fr[i].w,&fr[i].f);
//printf("%d %d %d %d\n",fr[i].i,fr[i].j,fr[i].w,fr[i].f);
if(fr[i].f)
{
//cout<<"这是通的"<<fr[i].i<<"
"<<fr[i].j<<endl;
int x=find1(fr[i].i);
int y=find1(fr[i].j);
//cout<<x<<" "<<y<<endl;
if(x!=y)
bin[x]=y;
}
}
int ans=kruskal(n,t);
printf("%d\n",ans);
}
return
0;
}
Problem E 的更多相关文章
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
- [LeetCode] Water and Jug Problem 水罐问题
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案
$s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...
随机推荐
- Python 接口测试(五)
五:使用python进行组织编写接口测试用例 接口测试其实就是几个步骤. 拿到接口的url地址 查看接口是用什么方式发送 添加请求头,请求体 发送查看返回结果,校验返回结果是否正确 明白了接口测试的测 ...
- WILL吃桃_KEY
WILL 吃桃 (peach.pas/c/cpp) [ 题目描述] Will 很喜欢吃桃, 某天 Will 来到了一片森林, 森林中有 N 颗桃树, 依次编号为 1,2,„,N.每棵树上有数量不等的桃 ...
- Opengl4.5 中文手册—A
因为opengl API 比较庞大,网络上还没有完整的.较新的opengl中文手册 这对很多人很不方便,所以整理了这一系列,用于帮助大家"快速浏览最新的opengl api" 为了 ...
- Java钉钉开发_02_免登授权(身份验证)(附源码)
源码已上传GitHub: https://github.com/shirayner/DingTalk_Demo 一.本节要点 1.免登授权的流程 (1)签名校验 (2)获取code,并传到后台 (3) ...
- HTML 简述
1.本页超链接 <a href="#t">查看 Chapter 4.</a> <a name="t">Test</a& ...
- 深入浅出AQS之条件队列
相比于独占锁跟共享锁,AbstractQueuedSynchronizer中的条件队列可能被关注的并不是很多,但它在阻塞队列的实现里起着至关重要的作用,同时如果想全面了解AQS,条件队列也是必须要学习 ...
- 『诡异的』VL10B创建外向交货单出错解决全过程
一直觉得SAP STO的业务模式配置起来还是挺简单的,无非就是关联一下采购单与交货单的关系,以及相应工厂的装运数据,其他像主数据的设置也没有什么特别的.相比ICS模式,它少了IDOC的配置,所以还是很 ...
- JavaWeb(一)Servlet中的ServletConfig与ServletContext
前言 前面我介绍了一下什么是servlet,它的生命周期,执行过程和它的原理.这里我们做一个简单的回顾! 什么是Servlet? servlet 是运行在 Web 服务器中的小型 Java 程序(即: ...
- Mybatis Dynamic Query 2.0.2
项目地址:https://github.com/wz2cool/mybatis-dynamic-query 文档地址:https://wz2cool.gitbooks.io/mybatis-dynam ...
- PHP常用字符串处理函数
(1)strlen(string) 返回字符串长度 (2)strpos(string,find,begin) 返回find字符串第一次出现的位置(从0开始) string:处理的字符串 find:想找 ...