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. SVN Working copy '***' locked

    问题描述: 用svn在项目文件夹下commit或者update时会出现错误提示“working copy locked” 解决方法: 1.在项目文件夹下,单击鼠标右键,选择tortoisesvn-&g ...

  2. centOS7虚拟机和本机ping通

    1.配置centOS虚拟机网卡 先设置桥接模式 此处的address要和本机的vmware在同一个网段 2.重启centOS网卡 3.关闭本机和虚拟机防火墙,防止ping不通 centOS命令: fi ...

  3. Mysql update后insert造成死锁原因分析及解决

    系统中出现死锁的日志如下: ) TRANSACTION: , ACTIVE sec inserting mysql tables , locked LOCK WAIT lock struct(s), ...

  4. RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍

    1. AMF AMF(是Action Message Format的缩写)是在flash和flex中与远程服务端交换数据的一种格式.它是二进制格式,Flash应用与服务端或数据库通过RPC交换数据时, ...

  5. HDU1430 BFS + 打表 + 康托展开

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1430 , 一道比较好的题. 这道题要用到很多知识,康托展开.BFS.打表的预处理还要用到一一映射,做完 ...

  6. webpack最简单的入门教程里bundle.js之运行单步调试的原理解析

    读这篇文章的朋友,请确保对webpack有最基础的认识. 您可以阅读我前一篇文章:Webpack 10分钟入门 来在本地运行一个Webpack的hello world项目.https://www.to ...

  7. Hybris Enterprise Commerce Platform 服务层的设计与实现

    Hybris Enterprise Commerce Platform这个系列之前已经由我的同事,SAP成都研究院Hybris开发团队的同事张健(Zhang Jonathan)发布过两篇文章了.这里J ...

  8. httpd2.4.6三种工作模式(如何配置),防止占用内存暴增的策略

    之前偷懒默认用yum安装了httpd.后来发现服务器内存暴增,一度达到75% 打开一看,好嘛后台休眠进程全是httpd. 重启之后再度访问发现内存还是稳步增长. [root@iz2ze3ayxs2yp ...

  9. FETCH - 用游标从查询中抓取行

    SYNOPSIS FETCH [ direction { FROM | IN } ] cursorname where direction can be empty or one of: NEXT P ...

  10. PostgreSql的使用

    title: PostgreSql的使用 tags: PostgreSql --- PostgreSql官网: https://www.postgresql.org/ 1 PostgreSql的安装 ...