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

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

下面就是怎么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. 题解 P1059 【明明的随机数】

    不会其他排序的小金羊又来水题了 本题我的思路:堆排,速度不需要算很快,AC就可以... 注意:初学者不宜抄此代码(压行严重) code: #include <cstdio> #includ ...

  2. Combining HTML5 Web Applications with OpenCV

    The Web Dev Zone is brought to you by Stormpath—offering a pre-built Identity API for developers. Ea ...

  3. Codeforces 582C. Superior Periodic Subarrays(数学+计数)

    首先可以把 i mod n=j mod n的看成是同一类,i mod s=j mod s的也看成是同一类,也就是i mod gcd(s,n)的是同一类,很好理解,但是不会数学证明...大概可以想成数轴 ...

  4. day5-python基础

  5. linux 进程信号集合 sigset_t

    sigset_t 号集及信号集操作函数:信号集被定义为一种数据类型: typedef struct { unsigned long sig[_NSIG_WORDS]: } sigset_t 信号集用来 ...

  6. 流媒体协议之JRTPLIB的使用20170919

    主要介绍JRTPLIB 2.x系列和3.x系列两种版本,它们的区别是2.x系列代码量少使用简单,但是只支持RFC 1889不支持RFC 3550,3.x支持RFC 3550,但代码量稍多,以及使用也稍 ...

  7. linux shell 通配符

    http://note.youdao.com/noteshare?id=4b6bc019e055c897c6dfb81fe2c17756

  8. (转) 使用vivado创建工程 3

    Create a Hello World application In this experiment we will use Xilinx SDK to create a simple Hello ...

  9. 洛谷P1124 文件压缩

    https://www.luogu.org/problem/show?pid=1124 题目背景 提高文件的压缩率一直是人们追求的目标.近几年有人提出了这样一种算法,它虽然只是单纯地对文件进行重排,本 ...

  10. CS48 D BIT

    统计一个点对应的和它严格右下方的点,点对数量.由于数据规模很大,不能直接上二维的前缀和,先排一维序,然后用BIT维护前缀和即可. /** @Date : 2017-09-14 20:17:30 * @ ...