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 ...
随机推荐
- jquery对象和js对象
<ul id="ul1"> <li id="li_1">01</li> <li>02</li> ...
- babel的使用详解
由于es6的很多特性在旧的浏览器下支持不好,我们在使用的时候需要将其转化为es5,下面介绍babel解析器的使用 一:独立使用babel的方法 1.本地安装babel-cli npm install ...
- Variational Bayes
一.前言 变分贝叶斯方法最早由Matthew J.Beal在他的博士论文<Variational Algorithms for Approximate Bayesian Inference> ...
- SQL server学习(一)数据库的基本知识、基本操作(分离、脱机、收缩、备份、还原、附加)和基本语法
在软件测试中,数据库是必备知识,共同探讨. 阅读目录 基本知识 数据库发展史 数据库名词 SQL组成 基本操作 登录数据库操作 数据库远程连接操作 数据库分离操作 数据库脱机.联机操作 数据库收缩操作 ...
- MMORPG战斗系统随笔(三)、AI系统简介
在设计一款游戏的时候,如果我们是玩家,是希望自己能够操作角色畅玩游戏的.在一款MMORPG游戏中,大部分的实际游戏角色,是需要玩家来操作的,通过在游戏大世界相互完成游戏中的任务等等来体验游戏.在大世界 ...
- 初学者易上手的SSH-struts2 01环境搭建
首先,SSH不是一个框架,而是多个框架(struts+spring+hibernate)的集成,是目前较流行的一种Web应用程序开源集成框架,用于构建灵活.易于扩展的多层Web应用程序. 集成SSH框 ...
- FPGA在其他领域的应用(三)
广播领域: 专业的A/V(音频/视频),和演播室行业正在经历着激动人心的变化,例如,UHD/8K (超高清)视频.多平台内容交付.IP网络传输和云计算.2016里约奥运会使用4K分辨率视频播放,而日本 ...
- Python二维数据分析
一.numpy二维数组 1.声明 import numpy as np #每一个[]代表一行 ridership = np.array([ [ 0, 0, 2, 5, 0], [1478, 3877, ...
- Promise 对象
Promise 对象用于处理异步请求,保存一个异步操作最终完成(或失败)的结果 语法 new Promise( /* executor */ function(resolve, reject) {.. ...
- c# gdi+输出成不同mime类型的图片
/// <summary> /// 通过图片的mime类型得到相应的编码器 /// </summary> /// <param name="mimeType&q ...