bzoj 4006: [JLOI2015]管道连接
Description
小铭铭最近进入了某情报部门,该部门正在被如何建立安全的通道连接困扰。
Input
第一行包含三个整数 n;m;p,表示情报站的数量,可以建立的通道数量和重要情报站的数
Output
输出一行一个整数,表示任意相同频道的情报站之间都建立通道连接所花费的最少资源总量。
Sample Input
1 2 3
1 3 2
1 5 1
2 4 2
2 5 1
3 4 3
3 5 1
4 5 1
1 1
1 2
2 3
2 4
Sample Output
HINT
选择 (1; 5); (3; 5); (2; 5); (4; 5) 这 4 对情报站连接。
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int N=,M=;
int gi(){
int str=;char ch=getchar();
while(ch>'' || ch<'')ch=getchar();
while(ch>='' && ch<='')str=(str<<)+(str<<)+ch-,ch=getchar();
return str;
}
int head[N],num=;
struct Lin{
int next,to,dis;
}a[M<<];
void init(int x,int y,int z){
a[++num].next=head[x];a[num].to=y;a[num].dis=z;head[x]=num;
}
int n,m,col,f[N][<<],P=,tot,INF;
bool vis[N];int q[N*],mod=N*;
void spfa(int k){
int t=,sum=,x,u;
for(int i=;i<=n;i++)
if(f[i][k]!=INF)q[++sum]=i,vis[i]=true;
while(t!=sum){
t++;if(t>=mod)t-=mod;x=q[t];
for(int i=head[x];i;i=a[i].next){
u=a[i].to;
if(f[x][k]+a[i].dis<f[u][k]){
f[u][k]=f[x][k]+a[i].dis;
if(!vis[u]){
vis[u]=true;
sum++;if(sum>=mod)sum-=mod;q[sum]=u;
}
}
}
vis[x]=false;
}
}
int ans[<<];int c[][],ts[<<];
bool check(int states){
for(int i=;i<=;i++){
if(!ts[i])continue;
if((ts[i]&states) && ((states&ts[i])!=ts[i]))return false;
}
return true;
}
void work(){
int x,y,z;
memset(f,/,sizeof(f));INF=f[][];
n=gi();m=gi();col=gi();
for(int i=;i<=m;i++){
x=gi();y=gi();z=gi();
init(x,y,z);init(y,x,z);
}
for(int i=;i<=col;i++){
x=gi();y=gi();
f[y][<<(P++)]=;
c[x][++c[x][]]=P-;
}
for(int i=;i<=;i++)
for(int j=,tmp=c[i][];j<=tmp;j++)
ts[i]|=(<<c[i][j]);
tot=(<<P)-;
for(int s=;s<=tot;s++){
for(int i=;i<=n;i++)
for(int j=(s-)&s;j;j=(j-)&s){
if(f[i][j]+f[i][s-j]<f[i][s]){
f[i][s]=f[i][j]+f[i][s-j];
}
}
spfa(s);
}
memset(ans,/,sizeof(ans));
for(int s=;s<=tot;s++)
for(int i=;i<=n;i++)
if(f[i][s]<ans[s])ans[s]=f[i][s];
for(int s=;s<=tot;s++){
if(!check(s)){
ans[s]=INF;
continue;
}
for(int j=(s-)&s;j;j=(j-)&s){
if(!check(j))continue;
ans[s]=min(ans[s],ans[j]+ans[s-j]);
}
}
printf("%d\n",ans[tot]);
}
int main()
{
freopen("pp.in","r",stdin);
work();
return ;
}
bzoj 4006: [JLOI2015]管道连接的更多相关文章
- bzoj 4006 [JLOI2015]管道连接(斯坦纳树+状压DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4006 [题意] 给定n点m边的图,连接边(u,v)需要花费w,问满足使k个点中同颜色的 ...
- bzoj 4006 [JLOI2015]管道连接——斯坦纳树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4006 除了模板,就是记录 ans[ s ] 表示 s 合法的最小代价.合法即保证 s 里同一 ...
- BZOJ 4006 [JLOI2015]管道连接(斯坦纳树+子集DP)
明显是一道斯坦纳树的题. 然而这题只需要属性相同的点互相连接. 我们还是照常先套路求出\(ans[s]\). 然后对\(ans[s]\)做子集DP即可. 具体看代码. #include<iost ...
- BZOJ4006 JLOI2015 管道连接(斯坦纳树生成森林)
4006: [JLOI2015]管道连接 Time Limit: 30 Sec Memory Limit: 128 MB Description 小铭铭最近进入了某情报部门,该部门正在被如何建立安全的 ...
- [BZOJ4006][JLOI2015]管道连接 状压dp+斯坦纳树
4006: [JLOI2015]管道连接 Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 1020 Solved: 552[Submit][Statu ...
- BZOJ_4006_[JLOI2015]管道连接_斯坦纳树
BZOJ_4006_[JLOI2015]管道连接_斯坦纳树 题意: 小铭铭最近进入了某情报部门,该部门正在被如何建立安全的通道连接困扰. 该部门有 n 个情报站,用 1 到 n 的整数编号.给出 m ...
- [bzoj4006][JLOI2015]管道连接_斯坦纳树_状压dp
管道连接 bzoj-4006 JLOI-2015 题目大意:给定一张$n$个节点$m$条边的带边权无向图.并且给定$p$个重要节点,每个重要节点都有一个颜色.求一个边权和最小的边集使得颜色相同的重要节 ...
- luogu P3264 [JLOI2015]管道连接
LINK:管道连接 一张无向图 有P个关键点 其中有K个集合 各个集合要在图中形成联通块 边有边权 求最小代价. 其实还是生成树问题 某个点要和某个点要在生成树中 类似这个意思. 可以发现 是斯坦纳树 ...
- BZOJ 4006 Luogu P3264 [JLOI2015]管道连接 (斯坦纳树、状压DP)
题目链接: (bzoj)https://www.lydsy.com/JudgeOnline/problem.php?id=4006 (luogu)https://www.luogu.org/probl ...
随机推荐
- 详谈C++虚函数表那回事(一般继承关系)
沿途总是会出现关于C++虚函数表的问题,今天做一总结: 1.什么是虚函数表: 虚函数(Virtual Function)是通过一张虚函数表(Virtual Table)来实现的.简称为V-Table. ...
- Mysql数据库的触发程序
/** **创建表 */ CREATE TABLE test1(a1 INT); CREATE TABLE test2(a2 INT); CREATE TABLE test3(a3 INT NOT N ...
- DML数据操作语言之常用函数
所谓函数,就是输入某一值,得到相应的输出结果的功能.相当于一个加工厂,给了原料,最终产出成品. 其中原料 就是参数(parameter). 产品 就是返回值. 函数大致可以分为以下五个种类: 算术函数 ...
- Java XML Dom解析工具
Java XML Dom解析工具 缩进等 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); ...
- LeetCode & Q66-Plus One-Easy
Array Description: Given a non-negative integer represented as a non-empty array of digits, plus one ...
- 用python实现与小米网关通讯
python 与小米网关通讯的三块内容: 以下内容的理解需要配合<绿米网关局域网通讯协议>使用 1.监听网关发出的组播信息:(有网关及连接设备的生命信号,事件信息) 2.读取需要获得的信息 ...
- ORA-00379 缓冲池 DEFAULT 中无法提供 32K 块大小的空闲缓冲区
(一)问题 今天在使用Pl/sql developer查看表空间大小的时候,报错误:ORA-00379 缓冲池 DEFAULT 中无法提供 32K 块大小的空闲缓冲区,具体如下图: SQL> s ...
- Linux CentOS7.0 (03)安装验证 docker
一.安装docker 1.升级 Linux 的软件包和内核 sudo yum update 2.安装 docker (1) sudo yum install docker (2).验证docker安 ...
- ios8新的api
self.navigationController.hidesBarsOnSwipe=YES; 滚动时隐藏导航栏
- Spring-cloud(二)注册服务提供者搭建
上文已经写了如何去搭建注册中心,仅有注册中心是远远不够的,所以我们需要注册到注册中心并提供服务的节点,这里称为注册服务提供者 前提 阅读上文,并成功搭建注册中心,环境无需改变 项目搭建 这里我们需要新 ...