HDU 4253 Two Famous Companies
Two Famous Companies
This problem will be judged on HDU. Original ID: 4253
64-bit integer IO format: %I64d Java class name: Main
Input
Output
Sample Input
2 2 1
0 1 1 1
0 1 2 0
2 2 0
0 1 1 1
0 1 2 0
Sample Output
Case 1: 2
Case 2: 1
In the first case, there are two cable plans between the only two cities, one from China Telecom and one from China Unicom. Mr. B needs to choose the one from China Telecom to satisfy the problem requirement even the cost is higher. In the second case, Mr. B must choose the cable from China Unicom, which leads the answer to 1.
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc{
int u,v,w,id;
arc(int uu = ,int vv = ,int ww = ,int iid = ){
u = uu;
v = vv;
w = ww;
id = iid;
}
bool operator<(const arc &tmp) const{
return w < tmp.w;
}
};
arc e[][maxn];
int uf[maxn],n,m,k,tot1,tot2,cost;
int Find(int x){
if(x == uf[x]) return x;
return uf[x] = Find(uf[x]);
}
bool uset(int u,int v){
int tx = Find(u);
int ty = Find(v);
if(tx != ty) uf[tx] = ty;
return tx != ty;
}
bool check(int delta){
int i,j,cnt;
for(i = ; i <= n; ++i) uf[i] = i;
i = j = cnt = cost = ;
arc tmp;
while(i < tot1 || j < tot2){
if(e[][i].w + delta <= e[][j].w){
tmp = e[][i++];
tmp.w += delta;
}else tmp = e[][j++];
if(uset(tmp.u,tmp.v)){
cost += tmp.w;
if(!tmp.id) cnt++;
}
}
return cnt >= k;
}
int main() {
int u,v,w,id,cs = ;
while(~scanf("%d %d %d",&n,&m,&k)){
for(int i = tot1 = tot2 = ; i < m; ++i){
scanf("%d %d %d %d",&u,&v,&w,&id);
if(id) e[][tot2++] = arc(u,v,w,id);
else e[][tot1++] = arc(u,v,w,id);
}
e[][tot1].w = e[][tot2].w = INF;
sort(e[],e[]+tot1);
sort(e[],e[]+tot2);
int low = -,high = ,mid,delta;
while(low <= high){
mid = (low + high)>>;
if(check(mid)){
delta = mid;
low = mid + ;
}else high = mid - ;
}
check(delta);
printf("Case %d: %d\n",cs++,cost - delta*k);
}
return ;
}
HDU 4253 Two Famous Companies的更多相关文章
- hdu 4253 Two Famous Companies BZOJ 2654 tree
[题意]:给出n个点,m条边,边分为两种,一种是A公司的,一种是B公司的.边上有权值,问用n-1条边把n个点连起来的最小费用是多少,其中A公司的边刚好有k条.题目保证有解. 思路:我们发现,如果我们给 ...
- HDOJ 4253 Two Famous Companies 二分+MST
题目意思:给出n个点,m条边,边分为两种,一种是A公司的,一种是B公司的.边上有权值, 问用n-1条边把n个点连起来的最小费用是多少,其中A公司的边刚好有k条.题目保证有解. 题解:题目意思很简单就是 ...
- HDU 4253-Two Famous Companies(二分+最小生成树)
Description In China, there are two companies offering the Internet service for the people from all ...
- hdu 4255 A Famous Grid
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4255 A Famous Grid Description Mr. B has recently dis ...
- HDU 4256 The Famous Clock
The Famous Clock Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4251 The Famous ICPC Team Again 主席树
The Famous ICPC Team Again Problem Description When Mr. B, Mr. G and Mr. M were preparing for the ...
- HDU 4294 A Famous Equation(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4249 题目大意:给一个a+b=c的表达式,但是a.b.c中部分位的数字丢失,并用?代替,问有多少种方案 ...
- HDU 4248 A Famous Stone Collector 组合数学dp ****
A Famous Stone Collector Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- HDU 4251 The Famous ICPC Team Again(划分树)
The Famous ICPC Team Again Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- A server is already running. Check tmp/pids/server.pid.
A server is already running. Check tmp/pids/server.pid. 把server.pid删除: 学习了: http://stackoverflow.co ...
- 使用SecueCRT在本地主机与远程主机之间交互文件
名词解释 本地主机:执行SecueCRT,以管理远程Linux或Unix的机器(一般为Windows系统) 远程主机:被SecueCRT进行管理控制的机器(一般为Linux或Unix) 1.开启SFT ...
- hadoop分布式架构和设计
引言 Hadoop分布式文件系统(HDFS)被设计成适合执行在通用硬件(commodity hardware)上的分布式文件系统.它和现有的分布式文件系统有非常多共同点.但同一时候,它和其它的分布式文 ...
- exFAT格式
买了一个64GB的T卡,发如今Windows XP上格式化."文件系统"仅仅有exFAT选项. 用这个exFAT格式化还失败了. 给XP打上KB955704补丁,能够用exFAT格 ...
- Android scrollTo() scrollBy() Scroller解说及应用
版本号:1.0 日期:2014.6.17 2014.6.18 版权:© 2014 kince 转载注明出处 scrollTo() .scrollBy()及 Scroller在视图滑动中常常使用 ...
- Spring经常使用属性的注入及属性编辑器
对于对象的注入,我们使用ref方式,能够指定注入的对象.以下看下对于基本类型的注入.以及当spring无法转换基本类型进行注入时,怎样编写一个相似转换器的东西来完毕注入. 一.基本类型的注入 以下写一 ...
- HDU 5654 xiaoxin and his watermelon candy 离线树状数组
xiaoxin and his watermelon candy Problem Description During his six grade summer vacation, xiaoxin g ...
- [yueqian_scut]Android多点触控技术和应用框架
Android多点触控技术跟Linux输入子系统紧密相关.本文将从应用的角度说明Android多点触控技术的接口和应用. 一.多点触控场景分析 网络上有关Android多点触控技术的文章多见于两点拉伸 ...
- php5.5安装笔记
这次没想到本来很简单的php编译,没想到遇到那么多问题.再此记录一下. 1.php5.5编译安装主要有一个难点,就是GD库的问题,因为php5.5的GD库必须是2.1以上的版本哦 原来都是用的gd2. ...
- HTML5-1、标签
本文只是自己学习HTML5时的一些笔记.希望自己能够学好HTML5. 如果有感兴趣的同学.可以互相学习. 我觉得HTML5在未来的开发中站主导地位. 下面开始学习HTML5. 还是从HTML5标签开始 ...