HDU1879 继续畅通工程 2017-04-12 19:12 50人阅读 评论(0) 收藏
继续畅通工程
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 92 Accepted Submission(s) : 43
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
当N为0时输入结束。
Output
Sample Input
3
1 2 1 0
1 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
Sample Output
3
1
0
Author
Source
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std; int m,n,pa[105];
struct node
{
int u,v,c;
} s[100005]; bool cmp(node a,node b)
{
return a.c<b.c;
} void init()
{
for(int i=0; i<105; i++)
pa[i]=i;
} int fin(int x)
{
if(pa[x]!=x)
{
pa[x]=fin(pa[x]);
}
return pa[x];
} void un(int a,int b)
{
int r1=fin(a);
int r2=fin(b);
if(r1!=r2)
{
pa[r1]=pa[r2];
}
} void kruskal()
{ int sum=0;
int num=0;
int flag=0;
for(int i=0; i<m; i++)
{
if(fin(s[i].u)!=fin(s[i].v))
{
un(s[i].u,s[i].v);
num++;
sum+=s[i].c;
if(num>=n-1)
{
flag=1;
break;
}
}
}
if(flag)
printf("%d\n",sum);
else
printf("?\n");
} int main()
{
int u,v,c,f;
while(scanf("%d",&n)&&n)
{
init();
m=n*(n-1)/2;
for(int i=0; i<m; i++)
{
scanf("%d%d%d%d",&u,&v,&c,&f);
s[i].u=u;
s[i].v=v;
s[i].c=c;
if(f==1)
s[i].c=0;
}
sort(s,s+m,cmp);
kruskal();
}
return 0;
}
HDU1879 继续畅通工程 2017-04-12 19:12 50人阅读 评论(0) 收藏的更多相关文章
- POJ1269 Intersecting Lines 2017-04-16 19:43 50人阅读 评论(0) 收藏
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 15478 Accepted: 67 ...
- HDU1875 畅通工程再续 2017-04-12 19:52 48人阅读 评论(0) 收藏
畅通工程再续 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submis ...
- HDU1233 还是畅通工程 2017-04-12 19:49 64人阅读 评论(0) 收藏
还是畅通工程 Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submis ...
- HDU1863 畅通工程 2017-04-12 19:25 59人阅读 评论(0) 收藏
畅通工程 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissi ...
- HDU1232 畅通工程 2017-04-12 19:20 53人阅读 评论(0) 收藏
畅通工程 Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissi ...
- 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...
- HDU6029 Happy Necklace 2017-05-07 19:11 45人阅读 评论(0) 收藏
Happy Necklace Time Limit: ...
- hdu 1053 (huffman coding, greedy algorithm, std::partition, std::priority_queue ) 分类: hdoj 2015-06-18 19:11 22人阅读 评论(0) 收藏
huffman coding, greedy algorithm. std::priority_queue, std::partition, when i use the three commente ...
- Python获取当前时间 分类: python 2014-11-08 19:02 132人阅读 评论(0) 收藏
Python有专门的time模块可以供调用. <span style="font-size:14px;">import time print time.time()&l ...
随机推荐
- winform 勾选可以改变框控件
public partial class UCCheck : UserControl { [Browsable(true), Category("修改属性"), Descripti ...
- vim自定义配置之自动括号
BundlenInstall安装auto-pairs vimConfig/plugin/auto-pairs-setting.vim let g:autopairsflymode=
- JWPlayer快速入门指南(中文)
将JW Player嵌入到网页中非常的简单,只需要进行如下3个步骤: 1.解压mediaplayer-viral.zip文件,将jwplayer.js和player.swf文件拷贝到工程中: 2.在页 ...
- 关于Class.getResource和ClassLoader.getResource的路径问题(转)
参考博客:http://www.cnblogs.com/yejg1212/p/3270152.html Class.getResource(String path) 当path以/开头,如/a/b/c ...
- 软件测试——等价类划分(EditText * 3)
一.程序要求 EditBox 同时允许输入三个1到6个英文字符或数字,点击确定结束. 二.测试分析 编号 第一个输入框 第二个输入框 第三个输入框 输出 1 null null null 三个输入框均 ...
- Linux内核优化(未注释)
Nginx代理服务内核优化 # Kernel sysctl configuration file for Red Hat Linux # # For binary values, 0 is disab ...
- tcpdf中文解决方案
步骤如下:1.确保你测试tcpdf能正常输出英文内容的pdf2.测试输入中文内容后显示是?的乱码或者空白分析原因,是因为我们输入的中文,tcpdf字体库并不支持,因此乱码或者空白显示 添加一个合适的字 ...
- iscroll源码学习(1)
iscroll是移端端开发的两大利器之一(另一个是fastclick),为了将它整合的avalon,需要对它认真学习一番.下面是我的笔记. 第一天看的是它的工具类util.js //用于做函数节流 v ...
- Navigation and Pathfinding
[Navigation and Pathfinding] 术语: 1)NavMesh 2)NavMesh Agent 3)Off-Mesh Link 4)NavMesh Obstacle A comm ...
- SimpleReflection
[SimpleReflection] 取法线的x.y作为reflection-map的uv. Shader "Custom/SimpleReflection" { Properti ...