ref

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;
int n, m, k, uu, vv, hea[105], cnt, tot[105];
ll b[105][1005], s[105][1005], w[105][105], bst[105][105], dis[105], ww;
bool ins[105];
const ll oo=0x3f3f3f3f3f3f3f3f;
queue<int> d;
struct Edge{
int too, nxt;
ll val;
}edge[20005];
void add_edge(int fro, int too, ll val){
edge[++cnt].nxt = hea[fro];
edge[cnt].too = too;
edge[cnt].val = val;
hea[fro] = cnt;
}
bool chk(ll lim){
memset(hea, 0, sizeof(hea));
memset(dis, 0, sizeof(dis));
while(!d.empty()) d.pop();
cnt = 0;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
if(bst[i][j]!=-1 && w[i][j]<oo)
add_edge(i, j, bst[i][j]-lim*w[i][j]);
for(int i=1; i<=n; i++){
d.push(i);
tot[i] = ins[i] = 1;
}
while(!d.empty()){
int x=d.front();
d.pop();
ins[x] = false;
for(int i=hea[x]; i; i=edge[i].nxt){
int t=edge[i].too;
if(dis[t]<=dis[x]+edge[i].val){//这里是大于等于,零环也合法
tot[t] = tot[x] + 1;
if(tot[t]>n) return true;
dis[t] = dis[x] + edge[i].val;
if(!ins[t]){
ins[t] = true;
d.push(t);
}
}
}
}
return false;
}
int main(){
memset(w, 0x3f, sizeof(w));
memset(bst, -1, sizeof(bst));
cin>>n>>m>>k;
for(int i=1; i<=n; i++)
for(int j=1; j<=k; j++)
scanf("%lld %lld", &b[i][j], &s[i][j]);
for(int i=1; i<=n; i++)
w[i][i] = 0;
for(int i=1; i<=m; i++){
scanf("%d %d %lld", &uu, &vv, &ww);
w[uu][vv] = min(w[uu][vv], ww);
}
for(int l=1; l<=n; l++)
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
w[i][j] = min(w[i][j], w[i][l]+w[l][j]); ll l=0, r=0, mid, re;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++){
if(i!=j && w[i][j]<oo){
bst[i][j] = 0;
for(int l=1; l<=k; l++)
if(s[j][l]!=-1 && b[i][l]!=-1)
bst[i][j] = max(bst[i][j], s[j][l]-b[i][l]);
r = max(r, bst[i][j]);
}
}
while(l<=r){
mid = (l + r) >> 1;
if(chk(mid)) re = mid, l = mid + 1;
else r = mid - 1;
}
cout<<re<<endl;
return 0;
}

loj2308 「APIO2017」商旅的更多相关文章

  1. 「APIO2017」商旅

    「APIO2017」商旅 题目描述 在广阔的澳大利亚内陆地区长途跋涉后,你孤身一人带着一个背包来到了科巴.你被这个城市发达而美丽的市场所深深吸引,决定定居于此,做一个商人.科巴有 \(N\) 个集市, ...

  2. 【LOJ】 #2308. 「APIO2017」商旅

    题解 分数题可以想到分数规划,我们预处理出从i到j卖什么货物赚的最多,然后把每条边的边权改成"利润 - 效率 × 时间" 用spfa找正环即可 代码 #include <bi ...

  3. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  4. 「译」JUnit 5 系列:扩展模型(Extension Model)

    原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...

  5. JavaScript OOP 之「创建对象」

    工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...

  6. 「C++」理解智能指针

    维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...

  7. 「JavaScript」四种跨域方式详解

    超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...

  8. 「2014-5-31」Z-Stack - Modification of Zigbee Device Object for better network access management

    写一份赏心悦目的工程文档,是很困难的事情.若想写得完善,不仅得用对工具(use the right tools),注重文笔,还得投入大把时间,真心是一件难度颇高的事情.但,若是真写好了,也是善莫大焉: ...

  9. 「2014-3-18」multi-pattern string match using aho-corasick

    我是擅(倾)长(向)把一篇文章写成杂文的.毕竟,写博客记录生活点滴,比不得发 paper,要求字斟句酌八股结构到位:风格偏杂文一点,也是没人拒稿的.这么说来,arxiv 就好比是 paper 世界的博 ...

随机推荐

  1. 淘宝H5移动端解决方案

    详细:http://www.w3cplus.com/mobile/lib-flexible-for-html5-layout.html ; (function(win, lib) { var doc ...

  2. 【迷你微信】基于MINA、Hibernate、Spring、Protobuf的即时聊天系统:8.自定义传输协议

    欢迎阅读我的开源项目<迷你微信>服务器)与<迷你微信>客户端 前言 在上一篇中,我们讲到了<迷你微信>服务器)的主体架构,还讲到了如何在现有功能上进行拓展,但是拓展 ...

  3. Flexbox与Grid属性比较

    网格容器(container)属性 网格项目(item)属性 Flex容器(container)属性 Flex项目(item)属性

  4. POJ 3734 Blocks (线性递推)

    定义ai表示红色和绿色方块中方块数为偶数的颜色有i个,i = 0,1,2. aij表示刷到第j个方块时的方案数,这是一个线性递推关系. 可以构造递推矩阵A,用矩阵快速幂求解. /*********** ...

  5. 五、react中父子组件间如何传值

    1.父组件向子组件传递数据:父组件绑定属性值传给子组件,子组件通过this.props()接受. 2.子组件向父组件传递数据:子组件绑定一个方法,方法中通过this.props.父组件方法名(参数)传 ...

  6. 问题 F: 等比数列

    问题 F: 等比数列 时间限制: 1 Sec  内存限制: 64 MB提交: 2699  解决: 1214[提交][状态][讨论版][命题人:外部导入] 题目描述 已知q与n,求等比数列之和: 1+q ...

  7. ubuntu or centos 网卡无法启动

    [root@seasoned-bro:/home/daeh0f]# /etc/init.d/network restart Restarting network (via systemctl): Jo ...

  8. convert命令

    可以修改图片的分辨率 convert -resize 600×600 src.jpg dst.jpg src.jpg是你要修改的图片的名字 dst.jpg是新生成的图片名字

  9. Java Web Application使Session永不失效(利用cookie隐藏登录)

    在做 Web Application 时,因为 Web Project 有 session 自动失效的问题,所以如何让用户登录一次系统就能长时间运行三个月,就是个问题. 后来,看到 session 失 ...

  10. Uva 派 (Pie,NWERC 2006,LA 3635)

    依然是一道二分查找 #include<iostream> #include<cstdio> #include<cmath> using namespace std; ...