这个题首先一眼能看出二分答案……

毕竟连可爱的边界都给你了。

下面就是怎么check

首先预处理跑一遍floyed,预处理出最短路。

用网络流判断能否达到即可。

#include<bits/stdc++.h>
typedef long long ll;
const int N=;
const int M=;
const int inf=1e9+;
using namespace std;
inline int read(){
int f=,x=;char ch;
do{ch=getchar();if(ch=='-')f=-;}while(ch<''||ch>'');
do{x=x*+ch-'';ch=getchar();}while(ch>=''&&ch<='');
return f*x;
}
namespace MaxFlow{ struct Edge{int u,v,next,f;}G[M];
int head[N],level[N],tot;
inline void init(){tot=;memset(head,,sizeof(head));}
inline void addedge(int u,int v,int f){
G[++tot].u=u;G[tot].v=v;G[tot].f=f;G[tot].next=head[u];head[u]=tot;
G[++tot].u=v;G[tot].v=u;G[tot].f=;G[tot].next=head[v];head[v]=tot;
}
inline bool bfs(int s,int t){
memset(level,,sizeof(level));queue<int>q;
q.push(s);level[s]=;
while(!q.empty()){
int u=q.front();q.pop();
if(u==t)return ;
for(int i=head[u];i;i=G[i].next){
int v=G[i].v,f=G[i].f;
if(f&&!level[v])level[v]=level[u]+,q.push(v);
}
}
return ;
}
inline int dfs(int u,int maxf,int t){
if(u==t)return maxf;int rat=;
for(int i=head[u];i;i=G[i].next){
int v=G[i].v,f=G[i].f;
if(f&&level[v]==level[u]+){
f=dfs(v,min(maxf-rat,f),t);
rat+=f;G[i].f-=f;G[i^].f+=f;
}
}
if(!rat)level[u]=inf;
return rat;
}
inline int dinic(int s,int t){
int ans=;
while(bfs(s,t))ans+=dfs(s,inf,t);
return ans;
} }
int n,m,p,q,f[N],dis[][];
inline bool check(int x){
MaxFlow::init();int s=,t=n*+;
for(int i=;i<=n;i++)MaxFlow::addedge(s,i,f[i]);
for(int i=;i<=n;i++)MaxFlow::addedge(i+n,t,);
for(int i=;i<=n;i++)if(f[i])for(int j=;j<=n;j++)
if(dis[i][j]<=x)MaxFlow::addedge(i,j+n,);
int ans=MaxFlow::dinic(s,t);
return ans>=q;
}
int main(){
n=read();m=read();p=read();q=read();
for(int i=;i<=p;i++){int x=read();f[x]++;}
memset(dis,0x3f,sizeof(dis));
for(int i=;i<=n;i++)dis[i][i]=;
for(int i=;i<=m;i++){
int u=read(),v=read(),w=read();dis[u][v]=dis[v][u]=min(dis[u][v],w);
}
for(int k=;k<=n;k++)for(int i=;i<=n;i++)for(int j=;j<=n;j++)
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
int l=,r=,ret=-;
while(l<=r){
int mid=(l+r)>>;
if(check(mid))r=mid-,ret=mid;
else l=mid+;
}
printf("%d\n",ret);
}

【BubbleCup X】D. Exploration plan的更多相关文章

  1. 【做题】HDU6331 Walking Plan——矩阵&分块

    题意:给出一个有\(n\)个结点的有向图,边有边权.有\(q\)组询问,每次给出\(s,t,k\),问从\(s\)到\(t\)至少经过\(k\)条边的最短路. \(n \leq 50, \, q \l ...

  2. 【BubbleCup X】F:Product transformation

    按照题解的规律,首先能看出前面每个数幂次的性质. 然后发掘约数的性质 #include<bits/stdc++.h> ; typedef long long ll; using names ...

  3. 【BubbleCup X】G:Bathroom terminal

    一个hash的题 对?出现位置直接暴力枚举,然后hash判断下,扔进map里 cf的评测机跑的针tm块 #include<bits/stdc++.h> ; ; typedef long l ...

  4. 【PAT甲级】1030 Travel Plan (30 分)(SPFA,DFS)

    题意: 输入N,M,S,D(N,M<=500,0<S,D<N),接下来M行输入一条边的起点,终点,通过时间和通过花费.求花费最小的最短路,输入这条路径包含起点终点,通过时间和通过花费 ...

  5. 【CF526G】Spiders Evil Plan(贪心)

    [CF526G]Spiders Evil Plan(贪心) 题面 洛谷 CodeForces 给定一棵树,要求选择\(y\)条链,满足被链覆盖的所有点在树上联通,且\(x\)必定在联通块中. 对于每次 ...

  6. 【codeforces 742C】Arpa's loud Owf and Mehrdad's evil plan

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【强化学习】1-1-2 “探索”(Exploration)还是“ 利用”(Exploitation)都要“面向目标”(Goal-Direct)

    title: [强化学习]1-1-2 "探索"(Exploration)还是" 利用"(Exploitation)都要"面向目标"(Goal ...

  8. 【Tsinghua OJ】多米诺骨牌(domino)问题

    (domino.c/cpp)[问题描述] 小牛牛对多米诺骨牌有很大兴趣,然而她的骨牌比较特别,只有黑色和白色的两种.她觉 得如果存在连续三个骨牌是同一种颜色,那么这个骨牌排列便是不美观的.现在她有n个 ...

  9. 【English Teradata】名称缩写

    日常缩写 [GTM]Teradata Go-to-Market employees [GTS]Teradata Global Technical Support [GSC] [CS&S]Cus ...

随机推荐

  1. bzoj4568-幸运数字

    题目 给出一棵树,每个节点上有权值\(a_i\),多次询问一条路径上选择一些点权值异或和最大值.\(n\le 2\times 10^4,q\le 2\times 10^5,0\le a_i\le 2\ ...

  2. 【HLSDK系列】HL引擎入门篇

    如果你打算拿HL的源码(也就是HLSDK)来改出一个自己的游戏,那你就非常有必要理解一些HL引擎的工作方式. HL引擎分成两个部分,服务端和客户端.服务端管理所有玩家的状态和游戏规则,客户端负责显示U ...

  3. 【bzoj4869】相逢是问候

    Portal-->bzoj4869 Solution 这道题的话..长得就是线段树的样子qwq 如果做过的话..可能会联想到bzoj3211(没写博qwq晚点再说吧哈哈..) 首先大胆猜一波结论 ...

  4. OpenCV图像变换(仿射变换与透视变换)

    仿射变换(affine transform)与透视变换(perspective transform)在图像还原.图像局部变化处理方面有重要意义.通常,在2D平面中,仿射变换的应用较多,而在3D平面中, ...

  5. 洛谷P1199 三国游戏

    题目描述 小涵很喜欢电脑游戏,这些天他正在玩一个叫做<三国>的游戏. 在游戏中,小涵和计算机各执一方,组建各自的军队进行对战.游戏中共有 N 位武将(N为偶数且不小于 4),任意两个武将之 ...

  6. [linux]linuxI/O测试的方法之dd

    参考http://www.thomas-krenn.com/en/wiki/Linux_I/O_Performance_Tests_using_dd Measuring Write Performan ...

  7. Ubuntu+NDK编译支持HTTPS的libcurl

    参考文章:1.NDK环境配置 http://blog.csdn.net/smfwuxiao/article/details/65877092.libcurl的配置修改 http://piggyq.co ...

  8. sourceTree的下载与安装

    一. SourceTree是什么? 一个拥有可视化界面的项目版本控制的软件,适用于git项目管理,在window和mac均可使用. 二. SourceTree下载 下载地址:SourceTree官网 ...

  9. OpenCV---ROI(region of interest)和泛洪填充

    一:ROI 感兴趣区(Region of Interest,ROIs) 是图像的一部分,它通过在图像上选择或使用诸如设定阈值(thresholding) 或者从其他文件(如矢量> 转换获得等方法 ...

  10. DES加密解密类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.S ...