题意:一副无向有权图,每个点有一些人,某些点是避难所(有容量),所有人要去避难所,问最小时间所有人都到达避难所,

题解:dij+二分+最大流check,注意到避难所最多10个,先挨个dij求到避难所的时间,然后二分时间,在这个时间之内的建边,s向避难所建边,流量是避难所容量,可达的避难所向点建边,流量inf,点向t建边,流量为人的个数,看能不能满流即可,wa点:maxflow里的inf忘改,maxn开小了= =

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 998244353
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const ull ba=233;
const db eps=1e-9;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+100,maxn=4000000+10,inf=0x3f3f3f3f; vector<pil>v[N];
ll d[12][N],a[N],b[20];
priority_queue<pli,vector<pli>,greater<pli>>q;
void dij(int s,int id)
{
memset(d[id],INF,sizeof d[id]);
d[id][s]=0;
q.push(mp(d[id][s],s));
while(!q.empty())
{
pli u=q.top();q.pop();
if(u.fi>d[id][u.se])continue;
for(pil x:v[u.se])
{
if(d[id][u.se]+x.se<d[id][x.fi])
{
d[id][x.fi]=d[id][u.se]+x.se;
q.push(mp(d[id][x.fi],x.fi));
}
}
}
}
struct edge{
int to,Next;
ll c;
}e[maxn];
int s,t,cnt,head[N],cur[N];
void init(){cnt=0;memset(head,-1,sizeof head);}
void add(int u,int v,ll c)
{
e[cnt].to=v;e[cnt].c=c;e[cnt].Next=head[u];head[u]=cnt++;
e[cnt].to=u;e[cnt].c=0;e[cnt].Next=head[v];head[v]=cnt++;
}
int dis[N];
bool bfs()
{
queue<int>q;
memset(dis,-1,sizeof dis);
dis[s]=1;q.push(s);
while(!q.empty())
{
int x=q.front();q.pop();
for(int i=head[x];~i;i=e[i].Next)
{
int y=e[i].to;
if(dis[y]==-1&&e[i].c>0)
{
dis[y]=dis[x]+1;
q.push(y);
}
}
}
return dis[t]!=-1;
}
ll dfs(int u,ll mx)
{
if(u==t)return mx;
ll flow=0,f;
for(int &i=cur[u];~i;i=e[i].Next)
{
int x=e[i].to;
if(dis[x]==dis[u]+1&&e[i].c>0&&(f=dfs(x,min(mx-flow,1ll*e[i].c))))
{
e[i].c-=f;
e[i^1].c+=f;
flow+=f;
if(flow==mx)break;
}
}
if(flow==0)dis[u]=-2;
return flow;
}
ll maxflow()
{
ll ans=0,f;
while(bfs())
{
for(int i=0;i<=t;i++)cur[i]=head[i];
while((f=dfs(s,INF)))ans+=f;
}
return ans;
}
int n,m,c;
bool ok(ll x)
{
init();s=n+c+1,t=n+c+2;
ll sum=0;
for(int i=1;i<=c;i++)
{
add(s,i,b[i]);
for(int j=1;j<=n;j++)if(d[i][j]<=x)add(i,c+j,INF);
}
for(int i=1;i<=n;i++)add(c+i,t,a[i]),sum+=a[i];
return maxflow()==sum;
}
int main()
{
scanf("%d%d%d",&n,&m,&c);
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
for(int i=1;i<=m;i++)
{
int a,b;ll c;scanf("%d%d%lld",&a,&b,&c);
v[a].pb(mp(b,c));v[b].pb(mp(a,c));
}
vector<ll>te;
for(int i=1,x;i<=c;i++)
{
scanf("%d%lld",&x,&b[i]),dij(x,i);
for(int j=1;j<=n;j++)te.pb(d[i][j]);
}
sort(te.begin(),te.end());te.erase(unique(te.begin(),te.end()),te.end());
int l=-1,r=te.size();
while(l<r-1)
{
int mid=(l+r)>>1;
if(ok(te[mid]))r=mid;
else l=mid;
}
printf("%lld\n",te[r]);
return 0;
}
/******************** ********************/

2018 Benelux Algorithm Programming Contest (BAPC 18)I In Case of an Invasion, Please. . .的更多相关文章

  1. 2018 Benelux Algorithm Programming Contest (BAPC 18)

    目录 Contest Info Solutions A A Prize No One Can Win B Birthday Boy C Cardboard Container D Driver Dis ...

  2. Gym -102007 :Benelux Algorithm Programming Contest (BAPC 18) (寒假自训第5场)

    A .A Prize No One Can Win 题意:给定N,S,你要从N个数中选最多是数,使得任意两个之和不大于S. 思路:排序,然后贪心的选即可. #include<bits/stdc+ ...

  3. 2014 Benelux Algorithm Programming Contest (BAPC 14)E

    题目链接:https://vjudge.net/contest/187496#problem/E E Excellent Engineers You are working for an agency ...

  4. 2017 Benelux Algorithm Programming Contest (BAPC 17) Solution

    A - Amsterdam Distance 题意:极坐标系,给出两个点,求最短距离 思路:只有两种方式,取min  第一种,先走到0点,再走到终点 第二种,走到同一半径,再走过去 #include ...

  5. 2015 Benelux Algorithm Programming Contest (BAPC 15)E - Excellent Engineers

    这题想了很久没思路,不知道怎么不sort维护二维的最小值 emmmm原来是线段树/树状数组,一维sort,二维当成下标,维护三维的最小值 #include<bits/stdc++.h> # ...

  6. 2018 German Collegiate Programming Contest (GCPC 18)

    2018 German Collegiate Programming Contest (GCPC 18) Attack on Alpha-Zet 建树,求lca 代码: #include <al ...

  7. (寒假GYM开黑)2018 German Collegiate Programming Contest (GCPC 18)

    layout: post title: 2018 German Collegiate Programming Contest (GCPC 18) author: "luowentaoaa&q ...

  8. Benelux Algorithm Programming Contest 2014 Final(第二场)

    B:Button Bashing You recently acquired a new microwave, and noticed that it provides a large number ...

  9. 2020.3.14--训练联盟周赛 Preliminaries for Benelux Algorithm Programming Contest 2019

    1.A题 题意:给定第一行的值表示m列的最大值,第m行的值表示n行的最大值,问是否会行列冲突 思路:挺简单的,不过我在一开始理解题意上用了些时间,按我的理解是输入两组数组,找出每组最大数,若相等则输出 ...

随机推荐

  1. SQL优化参考

    1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...

  2. FastQC结果详解

    REF https://www.plob.org/article/5987.html 解压后,查看html格式的结果报告.结果分为如下几项: 结果分为绿色的"PASS",黄色的&q ...

  3. sql 指定数据库中的信息操作

    查是否有该表名 SELECT * FROM sys.objects WHERE name='表名'查表字段的信息select * from syscolumns where id=Object_Id( ...

  4. P4980 【模板】Polya定理

    思路 polya定理的模板题,但是还要加一些优化 题目的答案就是 \[ \frac{\sum_{i=1}^n n^{gcd(i,n)}}{n} \] 考虑上方的式子怎么求 因为\(gcd(i,n)\) ...

  5. Optical Flow related Tutorials

    Optical Flow related Tutorials 2017-04-01 10:50:55 Reference: 1. http://blog.csdn.net/carson2005/art ...

  6. MPI之聚合通信-Scatter,Gather,Allgather

    转自:https://blog.csdn.net/sinat_22336563/article/details/70229243 参考:http://mpitutorial.com/tutorials ...

  7. HDU 1251 统计难题(字典树模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...

  8. 解决Geoserver请求跨域的几种思路,第二种思路用过

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景描述 跨域问题是浏览器同源安全制引起的特别常见的问题.不同前端语 ...

  9. 微信小游戏开发之JS面向对象

    //游戏开发之面向对象 //在js的开发模式中有两种模式:函数式+面向对象 //1.es5 // 拓展一:函数的申明和表达式之间的区别 // 函数的申明: // function funA(){ // ...

  10. Gson的fromJson()方法把json字符创转为实体

    直接上代码: 1.先看Person实体类 import lombok.Data; @Data public class Person { private String name; private in ...