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 ( ...
随机推荐
- ACdream 1229 Data Transmission
Data Transmission Special JudgeTime Limit: 12000/6000MS (Java/Others)Memory Limit: 128000/64000KB (J ...
- 开启WIFI
C:\Windows\system32>netsh wlan set hostednetwork mode=allow ssid=wuyechun-wifi k ey= 承载网络模式已设置为允许 ...
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第11章节--为Office和SP解决方式开发集成Apps 集成SP和Office App
BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第11章节--为Office和SP解决方式开发集成Apps 集成SP和Office App 你能够用两种 ...
- 安卓项目开发实战(1)--首页顶部菜单BAR实现
从今天開始,我将開始自己手写一个星座运势的项目,星座运势的数据来源採用MYAPI的星座数据,client全然自己实现. 这个系列主要是讲project中主要界面的布局展示和一些项目中的难点解析.因为本 ...
- linux下測试硬盘读写速度
买了个ssd硬盘,就想着跟普通的机械盘做个比較.由于桌面装的是ubuntu系统,所以就想用linux的命令简单測一下好了 以下是ssd的性能数据: 測试写: xxx@WaitFish:~ > t ...
- 2016.02.23,英语,《Vocabulary Builder》Unit 01
Bell:来源于拉丁语,含义为war.fight,其中Bellona [bә'lәunә]是罗马女战神的名字,她的丈夫是战神Mars.antebellum: [ˌænti'beləm] adj. 战前 ...
- Linux Mint (应用软件— 虚拟机:Virtualbox续)
我已经在当前的电脑中安装好了虚拟机.并且在虚拟机中安装了Ubuntu14.04LTS系统.接下来能够開始自己的折腾之旅了. 開始使用的时候总是感觉显示有问题,根据经验来看同,是系统分辨率设置不当引起的 ...
- DNS反射放大攻击分析——DNS反射放大攻击主要是利用DNS回复包比请求包大的特点,放大流量,伪造请求包的源IP地址为受害者IP,将应答包的流量引入受害的服务器
DNS反射放大攻击分析 摘自:http://www.shaojike.com/2016/08/19/DNS%E6%94%BE%E5%A4%A7%E6%94%BB%E5%87%BB%E7%AE%80%E ...
- EOJ 3124 单词表
题目描述 提取英文文本中的单词,重复出现的单词只取一个,把它们按照字典顺序排序,建立为一个单词表. 例如:英文文本如下: “ask not what your country can do for y ...
- WEBSERVICE之JDK开发webservice
转自:https://www.cnblogs.com/w-essay/p/7357262.html 一.开发工具与环境 1. jdk1.6版本以上(jdk1.6.0_21及以上版本) 2 .eclip ...