http://acm.hdu.edu.cn/showproblem.php?

pid=5294

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
 
Source

/**
hdu5294 最短路+最大流
题目大意:给定一个无向图,从起点到终点,仅仅有走最短路。才干在规定时限内到达,问最少去掉几条边使不能到达。最多去掉几条边仍能到达
解题思路:http://blog.sina.com.cn/s/blog_15139f1a10102vnx5.html 和官方题解想的一样
*/
#include<cstdio>
#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
const int oo=1e9;
const int mm=161111;
const int mn=2330;
int node,src,dest,edge;
int ver[mm],flow[mm],_next[mm];
int head[mn],work[mn],dis[mn],q[mn]; void prepare(int _node,int _src,int _dest)
{
node=_node,src=_src,dest=_dest;
for(int i=0; i<=node; ++i)head[i]=-1;
edge=0;
} void addedge(int u,int v,int c)
{
ver[edge]=v,flow[edge]=c,_next[edge]=head[u],head[u]=edge++;
ver[edge]=u,flow[edge]=0,_next[edge]=head[v],head[v]=edge++;
} bool Dinic_bfs()
{
int i,u,v,l,r=0;
for(i=0; i<node; ++i)dis[i]=-1;
dis[q[r++]=src]=0;
for(l=0; l<r; ++l)
for(i=head[u=q[l]]; i>=0; i=_next[i])
if(flow[i]&&dis[v=ver[i]]<0)
{
dis[q[r++]=v]=dis[u]+1;
if(v==dest)return 1;
}
return 0;
}
int Dinic_dfs(int u,int exp)
{
if(u==dest)return exp;
for(int &i=work[u],v,tmp; i>=0; i=_next[i])
if(flow[i]&&dis[v=ver[i]]==dis[u]+1&&(tmp=Dinic_dfs(v,min(exp,flow[i])))>0)
{
flow[i]-=tmp;
flow[i^1]+=tmp;
return tmp;
}
return 0;
}
int Dinic_flow()
{
int i,ret=0,delta;
while(Dinic_bfs())
{
for(i=0; i<node; ++i)work[i]=head[i];
while(delta=Dinic_dfs(src,oo))ret+=delta;
}
return ret;
} ///==================================================
const int INF=0x3f3f3f3f;
const int maxm=511111;
const int maxn=2111; struct EdgeNode
{
int to;
int w;
int next;
}; EdgeNode edges[maxm];
int N,M;
int head1[maxn],edge1;
bool vis[maxn];
queue <int> que;
int dis1[maxn],dis2[maxn]; void addedge1(int u,int v,int c)
{
edges[edge1].w=c,edges[edge1].to=v,edges[edge1].next=head1[u],head1[u]=edge1++;
} void init()
{
memset(head1,-1,sizeof(head1));
edge1=0;
} void spfa(int s,int n)//单源最短路(s为起点,n为节点总数)
{
int u;
for (int i=0; i<=n; i++)
dis1[i]=INF;
memset(vis,0,sizeof(vis));
while (!que.empty()) que.pop();
que.push(s);
vis[s]=true;
dis1[s]=0;
while (!que.empty())
{
u=que.front();
que.pop();
vis[u]=false;
for (int i=head1[u]; i!=-1; i=edges[i].next)
{
int v=edges[i].to;
int w=edges[i].w;
if (dis1[v]>dis1[u]+w)
{
dis1[v]=dis1[u]+w;
if (!vis[v])
{
vis[v]=true;
que.push(v);
}
}
}
}
}
////========================================
int aa[60080][3],bb[60080][3];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
init();
for(int i=0;i<m;i++)
{
scanf("%d%d%d",&aa[i][0],&aa[i][1],&aa[i][2]);
addedge1(aa[i][0],aa[i][1],aa[i][2]);
addedge1(aa[i][1],aa[i][0],aa[i][2]);
}
spfa(1,n);
memcpy(dis2,dis1,sizeof(dis1));
//printf("dis2->%d\n",dis2[n]);
spfa(n,n);
// printf("dis1->%d\n",dis1[1]);
int k=0;
for(int i=0;i<m;i++)
{
if(dis2[aa[i][0]]>dis2[aa[i][1]])
swap(aa[i][0],aa[i][1]);
// printf("n-%d:%d-1 %d %d %d\n",aa[i][1],aa[i][0],dis1[aa[i][1]],aa[i][2],dis2[aa[i][0]]);
if(dis1[aa[i][1]]+aa[i][2]+dis2[aa[i][0]]==dis2[n])
{
bb[k][0]=aa[i][0];
bb[k++][1]=aa[i][1];
// printf("%d %d\n",bb[k-1][0],bb[k-1][1]);
}
}
prepare(n+1,1,n);
for(int i=0;i<k;i++)
{
addedge(bb[i][0],bb[i][1],1);
}
int ans1=Dinic_flow();
init();
for(int i=0;i<k;i++)
{
addedge1(bb[i][0],bb[i][1],1);
addedge1(bb[i][1],bb[i][0],1);
}
spfa(1,n);
//printf("%d\n",dis2[n]);
int ans2=m-dis1[n];
printf("%d %d\n",ans1,ans2);
}
return 0;
}
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
 
Source

hdu5294||2015多校联合第一场1007 最短路+最大流的更多相关文章

  1. hdu 5288||2015多校联合第一场1001题

    pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...

  2. 2015 多校赛 第一场 1007 (hdu 5294)

    总算今天静下心来学算法.. Description Innocent Wu follows Dumb Zhang into a ancient tomb. Innocent Wu’s at the e ...

  3. hdu5289 2015多校联合第一场1002 Assignment

    题意:给出一个数列.问当中存在多少连续子区间,当中子区间的(最大值-最小值)<k 思路:设dp[i]为从区间1到i满足题意条件的解.终于解即为dp[n]. 此外 如果对于arr[i] 往左遍历 ...

  4. HDU 4865 Peter's Hobby(2014 多校联合第一场 E)(概率dp)

    题意:已知昨天天气与今天天气状况的概率关系(wePro),和今天天气状态和叶子湿度的概率关系(lePro)第一天为sunny 概率为 0.63,cloudy 概率 0.17,rainny 概率 0.2 ...

  5. HDU 4868 Information Extraction(2014 多校联合第一场 H)

    看到这道题时我的内心是奔溃的,没有了解过HTML,只能靠窝的渣渣英语一点一点翻译啊TT. Information Extraction 题意:(纯手工翻译,有些用词可能在html中不是一样的,还多包涵 ...

  6. HDU 5289 Assignment(多校联合第一场1002)

    Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  7. 2015 多校赛 第一场 1002 (hdu 5289)

    Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n ...

  8. 2015 多校赛 第一场 1001 (hdu 5288)

    Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l&l ...

  9. HDU 5724 Chess (状态压缩sg函数博弈) 2016杭电多校联合第一场

    题目:传送门. 题意:有n行,每行最多20个棋子,对于一个棋子来说,如果他右面没有棋子,可以移动到他右面:如果有棋子,就跳过这些棋子移动到后面的空格,不能移动的人输. 题解:状态压缩博弈,对于一行2^ ...

随机推荐

  1. php几个比较高级的函数

    1.传递任意数量的函数参数 我们在.NET或者JAVA编程中,一般函数参数个数都是固定的,但是PHP允许你使用任意个数的参数.下面这个示例向你展示了PHP函数的默认参数: 1 2 3 4 5 6 7 ...

  2. Python深入学习笔记(二)

    计数器Counter Counter类是自Python2.7起增加的,属于字典类的子类,是一个容器对象,主要用来统计散列对象,支持集合操作+.-.&.|,其中后两项分别返回两个Counter对 ...

  3. Window7 下开发php扩展

    一.首先查看phpinfo() 信息PHP Version 5.4.34Zend Extension Build     API220100525,TS,VC9 PHP Extension Build ...

  4. ASP.NET MVC轻教程 Step By Step 12——客户端验证

    前面两节使用的两种数据验证方法都是在服务器端进行的,也就是提交了表单,数据回传给服务器才能验证.这样会带来两个问题,一是用户体验不好,用户提交了表单之后才知道存在问题:二是会给服务器带来额外的压力.我 ...

  5. CAVLC

    在H.264标准中,CAVLC(Context-based Adaptive Variable Length Coding)被用于亮度和色度残差数据编码.在标准的码流结构中,CAVLC编码方式描述为c ...

  6. Java编程杂记

    13 Java Date 日期的使用方法 注意: 月份的设定要-1.0-代表1月:1代表2月,11代表12月. Calendar cal = new GregorianCalendar(2013,00 ...

  7. 【HDOJ】1829 A Bug's Life

    并查集变型.题意就是x与y是互斥的,下列是否数据是否可保证x-y是否均为互斥. #include <cstdio> #include <cstring> #define MAX ...

  8. xml中1字节的UTF-8序列的字节1无效([字符编码]Invalid byte 1 of 1-byte UTF-8 sequence终极解决方案)

    今天在eclipse中编写pom.xml文件时,注释中的中文被eclipse识别到错误:Invalid byte 1 of 1-byte UTF-8 sequence,曾多次遇到该问题,问题的根源是: ...

  9. Defining as a "long" or "int" type throws an error on startup

    solr启动时候,报如下异常: [java] view plaincopy SEVERE: org.apache.solr.common.SolrException          at org.a ...

  10. 每天一个linux命令:mkdir

    linux mkdir 命令用来创建指定的名称的目录,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录. 1.命令格式: mkdir [选项] 目录... 2.命令 ...