洛谷P3577 [POI2014]TUR-Tourism
给定一个n个点,m条边的无向图,其中你在第i个点建立旅游站点的费用为Ci。在这张图中,任意两点间不存在节点数超过10的简单路径。请找到一种费用最小的建立旅游站点的方案,使得每个点要么建立了旅游站点,要么与它有边直接相连的点里至少有一个点建立了旅游站点。
//minamoto
#include<iostream>
#include<cstdio>
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[<<],*p1=buf,*p2=buf;
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,:;}
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,:;}
inline int read(){
#define num ch-'0'
char ch;bool flag=;int res;
while(!isdigit(ch=getc()))
(ch=='-')&&(flag=true);
for(res=num;isdigit(ch=getc());res=res*+num);
(flag)&&(res=-res);
#undef num
return res;
}
const int N=,M=,SS=,inf=0x3f3f3f3f;
int head[N],Next[M],ver[M],tot;
int a[N],f[][SS],dep[N],vis[N],q[N],bin[],top,n,m,res;
inline void add(int u,int v){ver[++tot]=v,Next[tot]=head[u],head[u]=tot;}
inline int get(int S,int dep){return S/bin[dep]%;}
void dfs(int u,int d){
dep[u]=d,vis[u]=;
if(!d) f[][]=a[u],f[][]=,f[][]=inf;
else{
top=;
for(int i=head[u];i;i=Next[i])
if(vis[ver[i]]&&dep[ver[i]]<d) q[++top]=dep[ver[i]];
for(int S=;S<bin[d+];++S) f[d][S]=inf;
for(int S=bin[d]-;~S;--S){
int U=,V=S;
for(int i=;i<=top;++i){
int x=get(S,q[i]);
if(x==) U=;
else if(x==) V+=bin[q[i]];
}
cmin(f[d][S+U*bin[d]],f[d-][S]);
cmin(f[d][V],f[d-][S]+a[u]);
}
}
for(int i=head[u];i;i=Next[i]){
int v=ver[i];
if(!vis[v]){
dfs(v,d+);
for(int S=;S<bin[d+];++S)
f[d][S]=min(f[d+][S],f[d+][S+*bin[d+]]);
}
}
}
int main(){
// freopen("testdata.in","r",stdin);
bin[]=;for(int i=;i<=;++i) bin[i]=bin[i-]*;
n=read(),m=read();
for(int i=;i<=n;++i) a[i]=read();
for(int i=,u,v;i<=m;++i)
u=read(),v=read(),add(u,v),add(v,u);
for(int i=;i<=n;++i)
if(!vis[i]) dfs(i,),res+=min(f[][],f[][]);
printf("%d\n",res);
return ;
}
洛谷P3577 [POI2014]TUR-Tourism的更多相关文章
- 洛谷 P3580 - [POI2014]ZAL-Freight(单调队列优化 dp)
洛谷题面传送门 考虑一个平凡的 DP:我们设 \(dp_i\) 表示前 \(i\) 辆车一来一回所需的最小时间. 注意到我们每次肯定会让某一段连续的火车一趟过去又一趟回来,故转移可以枚举上一段结束位置 ...
- 洛谷 P3573 [POI2014]RAJ-Rally 解题报告
P3573 [POI2014]RAJ-Rally 题意: 给定一个\(N\)个点\(M\)条边的有向无环图,每条边长度都是\(1\). 请找到一个点,使得删掉这个点后剩余的图中的最长路径最短. 输入输 ...
- 洛谷P3572 [POI2014]PTA-Little Bird
P3572 [POI2014]PTA-Little Bird 题目描述 In the Byteotian Line Forest there are nn trees in a row. On top ...
- 洛谷——P3576 [POI2014]MRO-Ant colony
P3576 [POI2014]MRO-Ant colony 题目描述 The ants are scavenging an abandoned ant hill in search of food. ...
- 洛谷 P3576 [POI2014]MRO-Ant colony
P3576 [POI2014]MRO-Ant colony 题目描述 The ants are scavenging an abandoned ant hill in search of food. ...
- 洛谷P3576 [POI2014]MRO-Ant colony [二分答案,树形DP]
题目传送门 MRO-Ant colony 题目描述 The ants are scavenging an abandoned ant hill in search of food. The ant h ...
- 2018.09.14 洛谷P3567 [POI2014]KUR-Couriers(主席树)
传送门 简单主席树啊. 但听说有随机算法可以秒掉%%%(本蒟蒻并不会) 直接维护值域内所有数的出现次数之和. 当这个值不大于区间总长度的一半时显然不存在合法的数. 这样在主席树上二分查值就行了. 代码 ...
- 洛谷P3567[POI2014]KUR-Couriers(主席树+二分)
题意:给一个数列,每次询问一个区间内有没有一个数出现次数超过一半 题解: 最近比赛太多,都没时间切水题了,刚好日推了道主席树裸题,就写了一下 然后 WA80 WA80 WA0 WA90 WA80 ?? ...
- 【刷题】洛谷 P3573 [POI2014]RAJ-Rally
题目描述 An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long di ...
随机推荐
- C#语法复习1
一.C#与.net框架 .net是语言无关的. 程序的执行流程: .net兼容语言的源代码文件 .net兼容编译器 程序集(公共中间语言(CIL)common intermediate languag ...
- Linux安装Axis C构建WebService服务
在安装Axis C++之前有两个组件是必须安装的,分别是Apache HTTP Server以及用于处理XML的程序Xerces:为了编译Axis以及Apache HTTPD,你的Linux机器还应该 ...
- OpenStack Live Migration
About live migration of KVM virtual machines with NFS storage, from Mirantis blog: click this link w ...
- React Native安装
1.安装 1.1 安装Node.js 下载安装即可 1.2 安装Homebrew 终端中执行: $ /usr/bin/ruby -e "$(curl -fsSL https://raw.gi ...
- java上下文Context类
Context在Java中的出现是如此频繁,但其中文翻译"上下文"又是如此诡异拗口,因此导致很多人不是很了解Context的具体含义是指什么,所以很有必要来深究一下这词的含义. 先 ...
- link与import区别
本质上,这两种方式都是为了加载css文件,但还是存在细微的差别. 差别1:老祖宗的差别,link属于XHTML标签,而@import完全是css提供的一种方式. link标签除了可以加载css外,还可 ...
- react项目中的注意点
一.ES6 的编译方法 目前主流的浏览器还不支持ES6. 现在一般采用webpack 和 <script type="text/babel">对jsx 语法进行编译, ...
- HDU3652 B-number —— 数位DP
题目链接:https://vjudge.net/problem/HDU-3652 B-number Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- HDU1532 Drainage Ditches —— 最大流(sap算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 Drainage Ditches Time Limit: 2000/1000 MS (Java/ ...
- YTU 2578: 分数减法——结构体
2578: 分数减法--结构体 时间限制: 1 Sec 内存限制: 128 MB 提交: 522 解决: 399 题目描述 分数可以看成是由字符'/'分割两个整数构成,可以用结构体类型表示.请用结 ...