给一个图,求从某个点到另一个点的最短路有多少条?所有的路都不共边。

首先从终点开始Spfa标记最短距离,然后建图。

建图的时候,如果满足两点之间的最短路只差为两点之间的边长,那么在网络流的模型中连接一条边。

最终也只需要跑最大流即可。

注意此题没有要求不能经过同一个点,所有不需要拆点,由于我们在网络流的模型中间加边的时候边容量为1,也就保证了每条边只遍历一边了。

注意,有可能两个不同点之间的距离也为0,真是深坑啊,无法直视。

召唤代码君:

#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 111
#define maxm 44444
typedef long long ll;
using namespace std; ll inf=~0U>>;
ll to[maxm],next[maxm],c[maxm],first[maxn],edge;
ll d[maxn],tag[maxn],TAG=;
ll Q[maxm],bot,top;
ll ans,n,s,t;
ll dis[maxn][maxn],f[maxn];
bool can[maxn]; void _input()
{
for (ll i=; i<=n; i++)
{
f[i]=inf,first[i]=-;
for (ll j=; j<=n; j++) scanf("%lld",&dis[i][j]);
}
scanf("%lld%lld",&s,&t);
s++,t++;
Q[bot=top=]=t,f[t]=;
while (bot<=top)
{
ll cur=Q[bot++];
for (ll i=; i<=n; i++)
if (dis[i][cur]>= && f[cur]+dis[i][cur]<f[i])
f[i]=f[cur]+dis[i][cur],Q[++top]=i;
}
} void addedge(ll U,ll V)
{
edge++;
to[edge]=V,c[edge]=,next[edge]=first[U],first[U]=edge;
edge++;
to[edge]=U,c[edge]=,next[edge]=first[V],first[V]=edge;
} void build_graph()
{
edge=-;
for (int i=; i<=n; i++)
for (int j=; j<=n; j++)
if (i!=j && dis[i][j]>= && f[i]==f[j]+dis[i][j])
addedge(i,j);
} bool bfs()
{
Q[bot=top=]=t,d[t]=,tag[t]=++TAG,can[t]=false;
while (bot<=top)
{
ll cur=Q[bot++];
for (ll i=first[cur]; i!=-; i=next[i])
if (c[i^]> && tag[to[i]]!=TAG)
{
tag[to[i]]=TAG,can[to[i]]=false;
d[to[i]]=d[cur]+,Q[++top]=to[i];
if (to[i]==s) return true;
}
}
return false;
} ll dfs(ll cur,ll num)
{
if (cur==t) return num;
ll tmp=num,k;
for (ll i=first[cur]; i!=-; i=next[i])
if (c[i]> && tag[to[i]]==TAG && d[to[i]]==d[cur]- && !can[to[i]])
{
k=dfs(to[i],min(num,c[i]));
if (k) num-=k,c[i]-=k,c[i^]+=k;
if (num==) break;
}
if (num) can[cur]=true;
return tmp-num;
} int main()
{
inf*=inf;
while (scanf("%lld",&n)!=EOF)
{
_input();
if (s==t)
{
puts("inf");
continue;
}
build_graph();
for (ans=; bfs(); ) ans+=dfs(s,inf);
printf("%lld\n",ans);
}
return ;
}

ZOJ2760_How Many Shortest Path的更多相关文章

  1. hdu-----(2807)The Shortest Path(矩阵+Floyd)

    The Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  2. zoj 2760 How Many Shortest Path 最大流

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1760 Given a weighted directed graph ...

  3. The Shortest Path in Nya Graph

    Problem Description This is a very easy problem, your task is just calculate el camino mas corto en ...

  4. hdu 3631 Shortest Path(Floyd)

    题目链接:pid=3631" style="font-size:18px">http://acm.hdu.edu.cn/showproblem.php?pid=36 ...

  5. Shortest Path(思维,dfs)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  6. Shortest Path

    Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  7. (中等) HDU 4725 The Shortest Path in Nya Graph,Dijkstra+加点。

    Description This is a very easy problem, your task is just calculate el camino mas corto en un grafi ...

  8. 【ZOJ2760】How Many Shortest Path

    How Many Shortest Path 标签: 网络流 描述 Given a weighted directed graph, we define the shortest path as th ...

  9. [Swift]LeetCode847. 访问所有节点的最短路径 | Shortest Path Visiting All Nodes

    An undirected, connected graph of N nodes (labeled 0, 1, 2, ..., N-1) is given as graph. graph.lengt ...

随机推荐

  1. DB异常状态:Recovery Pending,Suspect,估计Recovery的剩余时间

    一,RECOVERY PENDING状态 今天修改了SQL Server的Service Account的密码,然后重启SQL Server的Service,发现有db处于Recovery Pendi ...

  2. Zabbix实战-简易教程--订阅类

    一.需求提出 最近数据中心有一个新的需求,有一批后台任务需要在每天固定时间点运行(凌晨8:00),现在希望能够把这个任务执行的结果定时上报给他. 说明:执行的任务为一个sql查询,查询出来的是每个任务 ...

  3. UWP 五星评价(不跳转到龟速商店)

    之前写过一篇文章  UWP 五星好评  代码如下 var pfn = Package.Current.Id.FamilyName; await Launcher.LaunchUriAsync(new ...

  4. Springboot日记——核心编码篇

    背景吐槽:想要让自己进阶一下,一定要有个可以拿出来秀的东西,所以要尝试写一个属于自己的网站或者平台.因此,我大概的看了一下springboot+Mybatis-plus+... 框架介绍 通常 SSM ...

  5. vue-cli 2.x和3.x安装的区别

    1.全局安装vue的脚手架:vue-cli(指定版本后面加@2.x.x) npm install -g vue-cli npm install -g @vue/cli 2.使用初始化 vue 项目: ...

  6. Bailian 2808 校门外的树(入门线段树)

    题目链接:http://bailian.openjudge.cn/practice/2808?lang=en_US 总时间限制: 1000ms 内存限制: 65536kB 描述 某校大门外长度为L的马 ...

  7. 3、ObjectARX开发创建直线、圆、圆弧和修改对象属性

    一.本节课程 Arx二次开发创建直线.圆.圆弧和修改对象属性 二.本节要讲解的知识点 1.如何应用C++ ARX二次开发创建直线. 2.如何应用C++ ARX二次开发创建圆. 3.如何应用C++ AR ...

  8. double类型四舍五入保留两位小数

    double x; int(x * 100 + 0.5) /100; 通过int强制转换截去后面的位数,实现两位小数保存, 由于强制转换直接把后面的信息截去,所以要想五入需要加0.5.

  9. golang slice使用不慎导致的问题

    原文链接 : http://www.bugclosed.com/post/16 背景 go语言中切片slice是方便且好用的强大数据结构,但是使用的时候需要注意,不然容易出问题,最近因为遇到了一个sl ...

  10. 随手记录-linux-Linux目录结构

    转:别人的 装完Linux,首先需要弄清Linux 标准目录结构 / root —?启动Linux时使用的一些核心文件.如操作系统内核.引导程序Grub等. home —?存储普通用户的个人文件 ft ...