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 ...
随机推荐
- GNU Radio: Multiple USRP configurations 配置多个USRP设备
Introduction 引言 Some USRP devices are capable of being grouped to form a single, virtual device. A s ...
- SpringCloud初体验:四、API GateWay 服务网关
网关服务很多,比如:Zuul.Kong.spring cloud gateway ……, 这里不纠结哪种性能好,本次体验是用的 spring cloud gateway 更多网关比较可以了解这篇文章: ...
- Ubuntu 16.04 natural scrolling
http://ubuntuhandbook.org/index.php/2016/05/install-ubuntu-tweak-in-ubuntu-16-04/ download ubuntu-tw ...
- Java中return的语句
1.return语句的作用:a.返回一个值,这个值可以是任意类型.b.使程序返回到操作系统(即终止程序)2.java中对于一个函数,不论有没有返回值类型,都可以带有return 语句.但是区别在于,r ...
- GCC参数详解 二
1简介 2简单编译 2.1预处理 2.2编译为汇编代码(Compilation) 2.3汇编(Assembly) 2.4连接(Linking) 3多个程序文件的编译 4检错 5库文件连接 5.1编译成 ...
- Quick guide for converting from JAGS or BUGS to NIMBLE
Converting to NIMBLE from JAGS, OpenBUGS or WinBUGS NIMBLE is a hierarchical modeling package that u ...
- js将UTC时间转化为当地时区时间(UTC转GMT)
我们在进行网站开发的时候有可能会涉及到国外的用户或者用户身在国外,这时就会存在时差问题,比如说我们在中国的时间是08:00,但是此时韩国的时间是09:00,如果在网页上需要进行相关显示的话就会出现问题 ...
- Blueprint 编译概述
转自:http://blog.csdn.net/cartzhang/article/details/39637269 一.术语 Blueprint,像C++语言一下的,在游戏中使用前需要编译.当你在B ...
- tensorflow-base_operations
# -*- coding: utf-8 -*-import tensorflow as tf# 基本的常量操作,通过构造函数返回值 定义值的操作operationsa = tf.constant(2) ...
- 「小程序JAVA实战」小程序视频组件与api介绍(51)
转自:https://idig8.com/2018/09/22/xiaochengxujavashizhanxiaochengxushipinzujianyuapijieshao50/ 这次说下,小程 ...