【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

第一问是个最短路。
第二问。
利用第一问floyd算出来的任意两点之间的最短路。
那么枚举每一条边(x,y)
如果w[1][x]+cost[x][y]+w[y][n]==w[1][n]
那么就说明(x->y)这条边是某条最短路上的必经边。
则我们在一张新的网络中加入(x,y,pi)这条边。
然后我们求这个网络的最小割。
那么1到n就没有办法通过最短路到达了,因为每条最短路都被破坏了。
讨论里好像说有重边。
pre[1]=0不能省。不然貌似会往回走。。

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std; const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int M = 15e4;
const int N = 500;
const int INF = 0x3f3f3f3f; struct abc{
int x,y,t,p;
}; int n,m,w[N+10][N+10],flow[N+10][N+10];
abc bian[M]; void add_edge(int x,int y,int z){
flow[x][y]+=z;
} queue<int> dl;
int pre[N+10]; int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
memset(w,0x3f3f3f3f,sizeof w);
cin >> n >> m;
rep1(i,1,n) w[i][i] = 0;
rep1(i,1,m) {
cin >> bian[i].x >> bian[i].y >> bian[i].t >> bian[i].p;
w[bian[i].x][bian[i].y] = min(w[bian[i].x][bian[i].y],bian[i].t);
w[bian[i].y][bian[i].x] = min(w[bian[i].y][bian[i].x],bian[i].t);
} rep1(k,1,n)
rep1(i,1,n)
if (i!=k)
rep1(j,1,n)
if (j!=k && j!= i && w[i][k]+w[k][j]<w[i][j])
w[i][j] = w[i][k]+w[k][j]; rep1(i,1,m){
int x = bian[i].x,y = bian[i].y,v = bian[i].t;
if (w[1][x]+w[y][n]+v == w[1][n]){
add_edge(x,y,bian[i].p);
}
if (w[1][y]+w[x][n]+v == w[1][n]){
add_edge(y,x,bian[i].p);
}
} cout<<w[1][n]<<endl; int ans = 0;
while (1){
memset(pre,255,sizeof pre);
while (!dl.empty()) dl.pop();
dl.push(1);
pre[1] = 0;
while (!dl.empty()){
int x = dl.front();dl.pop();
for (int i = 1;i <= n;i++)
if (pre[i]==-1 && x!=i && flow[x][i]>0){
pre[i] = x;
dl.push(i);
if (i==n) break;
}
}
if (pre[n]==-1) break;
int temp = 0x3f3f3f3f;
int y = n;
while (1){
int x = pre[y];
//cout<<x<<endl;
if (x==0) break;
temp = min(temp,flow[x][y]);
y = x;
} y = n;
while (1){
int x = pre[y];
if (x==0) break;
flow[x][y]-=temp;
flow[y][x]+=temp;
y = x;
} ans+=temp;
}
cout<<ans<<endl;
return 0;
}

最新文章

  1. Only Link: Inheritance and the prototype chain
  2. 东大OJ-1430-PrimeNumbers
  3. Windows Azure Table storage 之 动态Table类 DynamicTableEntity
  4. 完善DriveInfoEx源代码 获取计算机硬盘序列号
  5. POJ3349: Snowflake Snow Snowflakes(hash 表)
  6. Word 查找和替换的通配符
  7. URAL 2034 : Caravans
  8. Ajax实现三级联动(0520)
  9. offsetParent和parentNode区别
  10. func 和action 委托的使用
  11. struts2系列笔记(1)
  12. Mac系统下STF的环境搭建和运行
  13. 树莓派远程桌面配置-开机自启SSH
  14. 停止Flink任务
  15. 关于VS2017安装的一点扩充说明(15.5)
  16. UVA 11292 Dragon of Loowater(简单贪心)
  17. 特殊权限SUIG、SGID、SBIT
  18. MySQL性能调优——索引详解与索引的优化
  19. docker安装wnameless/oracle-xe-11g并运行(手写超详细)
  20. 安卓微信连接fiddler等抓包工具无法抓取https

热门文章

  1. java的值传递与引用传递
  2. CodeForcesGym 100641B A Cure for the Common Code
  3. 洛谷 1262 间谍网络 Tarjan 图论
  4. maven 创建web项目出错
  5. 使用Service Bus Topic 实现简单的聊天室
  6. CodeForces--606A --Magic Spheres(模拟水题)
  7. poj--3207--Ikki&#39;s Story IV - Panda&#39;s Trick(2-sat)
  8. 【BZOJ 2453】 维护队列
  9. Vmware VM共享
  10. 21.QT二进制文件