给定一个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的更多相关文章

  1. 洛谷 P3580 - [POI2014]ZAL-Freight(单调队列优化 dp)

    洛谷题面传送门 考虑一个平凡的 DP:我们设 \(dp_i\) 表示前 \(i\) 辆车一来一回所需的最小时间. 注意到我们每次肯定会让某一段连续的火车一趟过去又一趟回来,故转移可以枚举上一段结束位置 ...

  2. 洛谷 P3573 [POI2014]RAJ-Rally 解题报告

    P3573 [POI2014]RAJ-Rally 题意: 给定一个\(N\)个点\(M\)条边的有向无环图,每条边长度都是\(1\). 请找到一个点,使得删掉这个点后剩余的图中的最长路径最短. 输入输 ...

  3. 洛谷P3572 [POI2014]PTA-Little Bird

    P3572 [POI2014]PTA-Little Bird 题目描述 In the Byteotian Line Forest there are nn trees in a row. On top ...

  4. 洛谷——P3576 [POI2014]MRO-Ant colony

    P3576 [POI2014]MRO-Ant colony 题目描述 The ants are scavenging an abandoned ant hill in search of food. ...

  5. 洛谷 P3576 [POI2014]MRO-Ant colony

    P3576 [POI2014]MRO-Ant colony 题目描述 The ants are scavenging an abandoned ant hill in search of food. ...

  6. 洛谷P3576 [POI2014]MRO-Ant colony [二分答案,树形DP]

    题目传送门 MRO-Ant colony 题目描述 The ants are scavenging an abandoned ant hill in search of food. The ant h ...

  7. 2018.09.14 洛谷P3567 [POI2014]KUR-Couriers(主席树)

    传送门 简单主席树啊. 但听说有随机算法可以秒掉%%%(本蒟蒻并不会) 直接维护值域内所有数的出现次数之和. 当这个值不大于区间总长度的一半时显然不存在合法的数. 这样在主席树上二分查值就行了. 代码 ...

  8. 洛谷P3567[POI2014]KUR-Couriers(主席树+二分)

    题意:给一个数列,每次询问一个区间内有没有一个数出现次数超过一半 题解: 最近比赛太多,都没时间切水题了,刚好日推了道主席树裸题,就写了一下 然后 WA80 WA80 WA0 WA90 WA80 ?? ...

  9. 【刷题】洛谷 P3573 [POI2014]RAJ-Rally

    题目描述 An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long di ...

随机推荐

  1. 线段树区间更新,区间统计+离散化 POJ 2528 Mayor&#39;s posters

    题意:有一个非常长的板子(10000000长),在上面贴n(n<=10000)张海报.问最后从外面能看到几张不同的海报. 由于板子有10000000长,直接建树肯定会爆,所以须要离散化处理,对于 ...

  2. weex 项目开发(五)自定义 过滤函数 和 混合 及 自定义 Header 组件

    1.自定义  过滤函数 src / filters / index.js /** * 自定义 过滤函数 */ export function host (url) { if (!url) return ...

  3. weex 项目开发(二) weex 与 weexpack 的区别

    1.weex 与 weexpack 即  weex-toolkit 与 weexpack 的区别 weex-toolkit 初始化的项目是针对开发单个 Weex 页面而设计的,也就是说这样的项目只包括 ...

  4. 【leetcode】 26. Remove Duplicates from Sorted Array

    @requires_authorization @author johnsondu @create_time 2015.7.22 18:58 @url [remove dublicates from ...

  5. 如何干掉那些.ipch 与 .sdf文件

    参考资料: http://blog.163.com/yangjun1988422@126/blog/static/47412917201074446054/     vs2010中臃肿的ipch和sd ...

  6. 服务器----1U、2U、3U、4U

    U是一种表示服务器外部尺寸的单位,是unit的缩略语,详细的尺寸由作为业界团体的美国电子工业协会(EIA)所决定. 之所以要规定服务器的尺寸,是为了使服务器保持适当的尺寸以便放在铁质或铝质的机架上.机 ...

  7. HDU 1040 As Easy As A+B [补]

    今天去老校区找她,不想带电脑了,所以没时间A题了 /*******************************************************************/ As Ea ...

  8. 【 D3.js 进阶系列 — 1.2 】 读取 CSV 文件时乱码的解决方法

    在 D3 中使用 d3.csv 读取 CSV 文件时,有时会出现乱码问题. 怎么解决呢? 1. 乱码问题 使用 d3.csv 读取 xxx.csv 文件时.假设 xxx.csv 文件使用的是 UTF- ...

  9. 4.改变eclipse选中文字颜色

    window-preferences-general-editors-text editors-annotations-occurrences 和 window-preferences-general ...

  10. inheritance super overrides printMethod in Superclass override重写父方法

    Core Java Web Page http://horstmann.com/corejava.html [ inheritance ] package v1ch05.inheritance; im ...