【BubbleCup X】D. Exploration plan
这个题首先一眼能看出二分答案……
毕竟连可爱的边界都给你了。
下面就是怎么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的更多相关文章
- 【做题】HDU6331 Walking Plan——矩阵&分块
题意:给出一个有\(n\)个结点的有向图,边有边权.有\(q\)组询问,每次给出\(s,t,k\),问从\(s\)到\(t\)至少经过\(k\)条边的最短路. \(n \leq 50, \, q \l ...
- 【BubbleCup X】F:Product transformation
按照题解的规律,首先能看出前面每个数幂次的性质. 然后发掘约数的性质 #include<bits/stdc++.h> ; typedef long long ll; using names ...
- 【BubbleCup X】G:Bathroom terminal
一个hash的题 对?出现位置直接暴力枚举,然后hash判断下,扔进map里 cf的评测机跑的针tm块 #include<bits/stdc++.h> ; ; typedef long l ...
- 【PAT甲级】1030 Travel Plan (30 分)(SPFA,DFS)
题意: 输入N,M,S,D(N,M<=500,0<S,D<N),接下来M行输入一条边的起点,终点,通过时间和通过花费.求花费最小的最短路,输入这条路径包含起点终点,通过时间和通过花费 ...
- 【CF526G】Spiders Evil Plan(贪心)
[CF526G]Spiders Evil Plan(贪心) 题面 洛谷 CodeForces 给定一棵树,要求选择\(y\)条链,满足被链覆盖的所有点在树上联通,且\(x\)必定在联通块中. 对于每次 ...
- 【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 ...
- 【强化学习】1-1-2 “探索”(Exploration)还是“ 利用”(Exploitation)都要“面向目标”(Goal-Direct)
title: [强化学习]1-1-2 "探索"(Exploration)还是" 利用"(Exploitation)都要"面向目标"(Goal ...
- 【Tsinghua OJ】多米诺骨牌(domino)问题
(domino.c/cpp)[问题描述] 小牛牛对多米诺骨牌有很大兴趣,然而她的骨牌比较特别,只有黑色和白色的两种.她觉 得如果存在连续三个骨牌是同一种颜色,那么这个骨牌排列便是不美观的.现在她有n个 ...
- 【English Teradata】名称缩写
日常缩写 [GTM]Teradata Go-to-Market employees [GTS]Teradata Global Technical Support [GSC] [CS&S]Cus ...
随机推荐
- liunx 用户和用户组的命令
查看用户列表 /etc/passwd 查看用户组列表 /etc/group 用户和用户组管理 groupadd groups 新增用户组 groupmod -n newgroupsr gro ...
- 在洛谷3369 Treap模板题 中发现的Splay详解
本题的Splay写法(无指针Splay超详细) 前言 首先来讲...终于调出来了55555...调了整整3天..... 看到大部分大佬都是用指针来实现的Splay.小的只是按照Splay的核心思想和原 ...
- Codeforces Round #362(Div1) D Legen...(AC自动机+矩阵快速幂)
题目大意: 给定一些开心串,每个串有一个开心值,构造一个串,每包含一次开心串就会获得一个开心值,求最大获得多少开心值. 题解: 首先先建立AC自动机.(建立fail指针的时候,对val要进行累加) 然 ...
- Oracle Parameter使用
string sqlStr = "update sys_case t set t.content =:CONTENT,t.property=:PROPERTY where id=:ID&qu ...
- PHP关于VC9和VC6以及Thread Safe和Non Thread Safe版本选择的问题
一.如何选择PHP5.3的VC9版本和VC6版本 VC6版本是使用Visual Studio 6编译器编译的,如果你的PHP是用Apache来架设的,那你就选择VC6版本. VC9版本是使用 ...
- Kerberos的黄金票据详解
0x01黄金票据的原理和条件 黄金票据是伪造票据授予票据(TGT),也被称为认证票据.如下图所示,与域控制器没有AS-REQ或AS-REP(步骤1和2)通信.由于黄金票据是伪造的TGT,它作为TGS- ...
- 电子商务(电销)平台中财务模块(Finance)数据库设计明细
以下是自己在电子商务系统设计中的数据库设计经验总结,而今发表出来一起分享,如有不当,欢迎跟帖讨论~ 资金账户表 (finance_account)|-- 自动编号|-- 用户编号|-- 预付款 (ad ...
- XSS/CSRF跨站攻击和防护方案
Xss(Cross Site Scripting 跨站脚本攻击)/CSRF(Cross-site request forgery 跨站请求伪造),它与著名的SQL注入攻击类似,都是利用了Web页面的编 ...
- 【数据结构】【平衡树】treap
之前写treap的传送门 之前写的那个太毒瘤了,这次放一个更毒瘤的指针版上来 #include<cstdio> #include<iostream> #define rg re ...
- spring mybatis 多数据源配置
1.创建好数据库的配置文件 mysql.url=jdbc:mysql://***/***?useUnicode=true&characterEncoding=UTF-8 mysql.usern ...