博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ3068:"Shortest" pair of paths——题解
阅读量:7073 次
发布时间:2019-06-28

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

题目大意:

从0~n-1找到两条边和点都不相同(除了0和n-1外)的最小费用路径。

————————————————————————————

魔改版。

按照那题的思路并且把点拆成中间连一条容量为1的边即可。

切了切了。

#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;const int INF=1e9;const int N=70;const int M=20100;inline int read(){ int X=0,w=0;char ch=0; while(!isdigit(ch)){w|=ch=='-';ch=getchar();} while(isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); return w?-X:X;}struct node{ int nxt; int to; int w; int b;}edge[M];int head[N],cnt=-1;void add(int u,int v,int w,int b){ cnt++; edge[cnt].to=v; edge[cnt].w=w; edge[cnt].b=b; edge[cnt].nxt=head[u]; head[u]=cnt; return;}int dis[N];bool vis[N];inline bool spfa(int s,int t,int n){ deque
q; memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++)dis[i]=INF; dis[t]=0;q.push_back(t);vis[t]=1; while(!q.empty()){ int u=q.front(); q.pop_front();vis[u]=0; for(int i=head[u];i!=-1;i=edge[i].nxt){ int v=edge[i].to; int b=edge[i].b; if(edge[i^1].w&&dis[v]>dis[u]-b){ dis[v]=dis[u]-b; if(!vis[v]){ vis[v]=1; if(!q.empty()&&dis[v]

 

转载于:https://www.cnblogs.com/luyouqi233/p/7953601.html

你可能感兴趣的文章
QPID spring 示例
查看>>
自动优化mycncart和opencart所有数据库
查看>>
快速充电技术介绍
查看>>
Laravel4 入门一
查看>>
shell学习链接
查看>>
适配多种数据结构和ui的万能适配器
查看>>
Spring Boot自定义Starter模块开发
查看>>
java.net.NoRouteToHostException: No route to host
查看>>
有限维度的向量空间
查看>>
java thirteen线程同步机制
查看>>
微信小程序教程、微信小程序开发资源下载汇总(6.16日更新,持续更新中……)...
查看>>
CentOS 6.3 安装Mysql 整理
查看>>
电脑中安装多个版本的JDK后的切换
查看>>
Docker入门与实战系列:生态系统
查看>>
.net mysql
查看>>
常用算法之二分查询python&php
查看>>
Securing Web Applications with Apache Shiro(2)
查看>>
boost学习之--shared_ptr
查看>>
python 学习网站
查看>>
Centos7 install python-rrdtoll-1.47 erro
查看>>