博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDOJ 5294 Tricks Device 最短路(记录路径)+最小割
阅读量:6758 次
发布时间:2019-06-26

本文共 4212 字,大约阅读时间需要 14 分钟。

最短路记录路径,同一时候求出最短的路径上最少要有多少条边,

然后用在最短路上的边又一次构图后求最小割.

Tricks Device

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1584    Accepted Submission(s): 388


Problem Description
Innocent Wu follows Dumb Zhang into a ancient tomb. Innocent Wu’s at the entrance of the tomb while Dumb Zhang’s at the end of it. The tomb is made up of many chambers, the total number is N. And there are M channels connecting the chambers. Innocent Wu wants to catch up Dumb Zhang to find out the answers of some questions, however, it’s Dumb Zhang’s intention to keep Innocent Wu in the dark, to do which he has to stop Innocent Wu from getting him. Only via the original shortest ways from the entrance to the end of the tomb costs the minimum time, and that’s the only chance Innocent Wu can catch Dumb Zhang.
Unfortunately, Dumb Zhang masters the art of becoming invisible(奇门遁甲) and tricks devices of this tomb, he can cut off the connections between chambers by using them. Dumb Zhang wanders how many channels at least he has to cut to stop Innocent Wu. And Innocent Wu wants to know after how many channels at most Dumb Zhang cut off Innocent Wu still has the chance to catch Dumb Zhang.
 

Input
There are multiple test cases. Please process till EOF.
For each case,the first line must includes two integers, N(<=2000), M(<=60000). N is the total number of the chambers, M is the total number of the channels.
In the following M lines, every line must includes three numbers, and use ai、bi、li as channel i connecting chamber ai and bi(1<=ai,bi<=n), it costs li(0<li<=100) minute to pass channel i.
The entrance of the tomb is at the chamber one, the end of tomb is at the chamber N.
 

Output
Output two numbers to stand for the answers of Dumb Zhang and Innocent Wu’s questions.
 

Sample Input
 
8 9 1 2 2 2 3 2 2 4 1 3 5 3 4 5 4 5 8 1 1 6 2 6 7 5 7 8 1
 

Sample Output
 
2 6
 

Author
FZUACM
 

Source
 
/* ***********************************************Author        :CKbossCreated Time  :2015年07月24日 星期五 10时07分09秒File Name     :HDOJ5294.cpp************************************************ */#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef pair
pII;const int INF=0x3f3f3f3f;const int maxn=2200;int n,m;/*************EDGE********************/struct Edge{ int to,next,cost,cap,flow;}edge[maxn*60],edge2[maxn*60];int Adj[maxn],Size;int Adj2[maxn],Size2;void Add_Edge(int u,int v,int c){ edge[Size].to=v; edge[Size].next=Adj[u]; edge[Size].cost=c; Adj[u]=Size++;}/********spfa************/int dist[maxn];bool inQ[maxn];vector
Pre[maxn];int spfa(Edge* edge,int* Adj){ memset(dist,63,sizeof(dist)); memset(inQ,false,sizeof(inQ)); dist[1]=0; queue
q; inQ[1]=true;q.push(1); while(!q.empty()) { int u=q.front();q.pop(); for(int i=Adj[u];~i;i=edge[i].next) { int v=edge[i].to; if(dist[v]>dist[u]+edge[i].cost) { Pre[v].clear(); Pre[v].push_back(u); dist[v]=dist[u]+edge[i].cost; if(!inQ[v]) { inQ[v]=true; q.push(v); } } else if(dist[v]==dist[u]+edge[i].cost) { Pre[v].push_back(u); } } inQ[u]=false; } return dist[n];}/********************rebuild************************/void Add_Edge2(int u,int v,int w,int rw=0){ edge2[Size2].cost=1; edge2[Size2].to=v; edge2[Size2].cap=w; edge2[Size2].next=Adj2[u]; edge2[Size2].flow=0; Adj2[u]=Size2++; edge2[Size2].cost=1; edge2[Size2].to=u; edge2[Size2].cap=w; edge2[Size2].next=Adj2[v]; edge2[Size2].flow=0; Adj2[v]=Size2++;}bool used[maxn];int edges;void rebuild(){ memset(used,false,sizeof(used)); queue
q; q.push(n); used[n]=true; edges=0; while(!q.empty()) { int v=q.front(); q.pop(); for(int i=0,sz=Pre[v].size();i
v //cout<
<<" ---> "<
<
edge[i].cap-edge[i].flow) Min=edge[i].cap-edge[i].flow; } for(int i=pre[u];~i;i=pre[edge[i^1].to]) { edge[i].flow+=Min; edge[i^1].flow-=Min; } u=start; ans+=Min; continue; } bool flag=false; int v; for(int i=cur[u];~i;i=edge[i].next) { v=edge[i].to; if(edge[i].cap-edge[i].flow&&dep[v]+1==dep[u]) { flag=true; cur[u]=pre[v]=i; break; } } if(flag) { u=v; continue; } int Min=N; for(int i=Adj2[u];~i;i=edge[i].next) { if(edge[i].cap-edge[i].flow&&dep[edge[i].to]

转载地址:http://dfweo.baihongyu.com/

你可能感兴趣的文章
Exchange server 2010 安装部署之二,Exchange2010安装详解
查看>>
负载均衡集群之LVS
查看>>
本地计算机无法启动Server服务
查看>>
Compellent SAN存储解决方案
查看>>
优秀前端工程师需要做的10件事
查看>>
Python——异常(内置异常以及应用场景)
查看>>
IT运维服务 - 数据库监控和日常维护项目
查看>>
在java-Hibernate关系映射之关联映射知识描述
查看>>
java整理知识点
查看>>
软件开发人员想找的工作,随便聊聊,娱乐大家,请补充补充
查看>>
DAY08 NETWORK CISCO简单通信
查看>>
jQuery学习小结3——AJAX
查看>>
MYSQL 字符集问题
查看>>
我的友情链接
查看>>
Android学习笔记-基于HTTP的通信技术
查看>>
saltstack 使用总结
查看>>
我的友情链接
查看>>
Sed实例二
查看>>
我的友情链接
查看>>
第三方备份虚拟机发生错误 附批量修改vmx参数脚本
查看>>