[BalticOI2002]Bicriterial routing
OJ题号:
BZOJ1375、ECNU1468
题目大意:
给定一个无向连通图,每条边有两个权值w1和w2。定义一条路径是优秀的当且仅当没有别的路径满足两个权值的和都比该路径小,求s到t的优秀路径条数。
思路:
将其中一个权值转化为最短路的一个维度,也就是求出对于同一个结点的不同的w1的和,最小的w2和。
然后直接跑Dijkstra就可以了。
1 #include<cstdio> 2 #include<cctype> 3 #include<vector> 4 #include<functional> 5 #include<ext/pb_ds/priority_queue.hpp> 6 inline int getint() { 7 register char ch; 8 while(!isdigit(ch=getchar())); 9 register int x=ch^'0'; 10 while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0'); 11 return x; 12 } 13 const int inf=0x7fffffff; 14 const int V=101,W=101; 15 struct Edge { 16 int to,w1,w2; 17 }; 18 std::vector<Edge> e[V]; 19 inline void add_edge(const int &u,const int &v,const int &w1,const int &w2) { 20 e[u].push_back((Edge){v,w1,w2}); 21 } 22 int n,m,s,t; 23 struct Vertex { 24 int dis,id,w; 25 bool operator > (const Vertex &another) const { 26 return dis>another.dis; 27 } 28 }; 29 int d[V][(V-1)*W]; 30 __gnu_pbds::priority_queue<Vertex,std::greater<Vertex>> q; 31 __gnu_pbds::priority_queue<Vertex,std::greater<Vertex>>::point_iterator p[V][V*W]; 32 inline void dijkstra() { 33 for(register int i=1;i<=n;i++) { 34 for(register int j=0;j<(n-1)*W;j++) { 35 p[i][j]=q.push((Vertex){d[i][j]=(i==s&&j==0)?0:inf,i,j}); 36 } 37 } 38 while(q.top().dis!=inf) { 39 const Vertex x=q.top(); 40 for(register unsigned i=0;i<e[x.id].size();i++) { 41 const Edge &y=e[x.id][i]; 42 if((x.w+y.w1)<(n-1)*W&&(x.dis+y.w2)<d[y.to][x.w+y.w1]) { 43 q.modify(p[y.to][x.w+y.w1],(Vertex){d[y.to][x.w+y.w1]=x.dis+y.w2,y.to,x.w+y.w1}); 44 } 45 } 46 q.modify(p[x.id][x.w],(Vertex){inf,x.id,x.w}); 47 } 48 q.clear(); 49 } 50 int main() { 51 n=getint(),m=getint(),s=getint(),t=getint(); 52 for(register int i=1;i<=m;i++) { 53 int u=getint(),v=getint(),t=getint(),c=getint(); 54 add_edge(u,v,t,c); 55 add_edge(v,u,t,c); 56 } 57 dijkstra(); 58 int ans=0,min=inf; 59 for(register int i=0;i<(n-1)*W;i++) { 60 if(d[t][i]==inf) continue; 61 if(d[t][i]<min) { 62 ans++; 63 min=d[t][i]; 64 } 65 } 66 printf("%d\n",ans); 67 return 0; 68 }
转载于:https://www.cnblogs.com/skylee03/p/7561128.html
[BalticOI2002]Bicriterial routing相关推荐
- RabbitMQ 入门系列(11)— RabbitMQ 常用的工作模式(simple模式、work模式、publish/subscribe模式、routing模式、topic模式)
1. simple 模式 simple 模式是最简单最常用的模式 2. work 模式 work 模式有多个消费者 消息产生者将消息放入队列.生产者系统不需知道哪一个任务执行系统在空闲,直接将任务扔到 ...
- 一步步学会使用ASP.NET 4 WEB应用程序中使用URL Routing(翻译)
创建路由 路由就是将URL路径映射到具体的物理文件.若要将路由添加到网站中,请使用 RouteCollection.MapPageRoute 方法将它们添加到RouteTable类的静态Routes属 ...
- Follow Me:CCIE RS--新版CCIE Routing Switching 考纲要点
新版CCIE Routing & Switching 考纲要点: Switching * Catalyst Switch 3550 configuration * Config ...
- [BTS2004]一步一步学习BizTalk2004 CBR(content-based routing)
CBR ( content-based routing ) CBR 可以实现将指定的消息内容进行路由处理 在这个例子中,可以实现将传入的消息,对指定的内容进行筛选,把满足条件的消息传输到指定的路径下 ...
- ASP.NET MVC 入门3、Routing
本系列文章基于Microsoft ASP.NET MVC Beta. 在一个route中,通过在大括号中放一个占位符来定义( { and } ).当解析URL的时候,符号"/"和& ...
- WCF4.0新特性体验(6):路由服务Routing Service(下)
紧接前文WCF4.0新特性体验(5):路由服务Routing Service(上).今天我们介绍WCF4.0消息路由的实现机制,然后会讲解路由服务的实现过程. [4]WCF与路由服务: 其实在介绍WC ...
- 路由设计技术基础(Fundamentals of routing design technology)
路由设计技术基础(Fundamentals of routing design technology) UDP(User Datagram Protocol) FUNCTION TCP(Transmi ...
- Segment Routing — SRv6 — SRv6 协议解析
目录 文章目录 目录 SRv6 的核心概念 SRv6 的报文结构 SRv6 SRH 的报文结构 SRv6 SRH SID 的报文结构 SRv6 Routing(Locator) SRv6 Behavi ...
- Segment Routing — SRv6 — 统一的 SDN 控制面与数据面
目录 文章目录 目录 MPLS L3VPN over SRv6 EVPN L3VPN over SRv6 EVPN VPWS over SRv6 EVPN VPLS over SRv6 MPLS L3 ...
- Segment Routing — SR-MPLS
目录 文章目录 目录 SR-MPLS v.s. MPLS SR-MPLS SR-MPLS 的转发原理 SR-MPLS 的控制面 IGP Prefix/Node Segment IGP Adjacenc ...
最新文章
- Linux下mysql支持中文,linux下mysql环境支持中文配置步骤
- jdbc连接oracle rac服务器
- SWFLibrary类加载外部资源库
- fastdfs 测试客户端_Nginx+FastDFS+MacOS图片服务器的搭建
- python调用ipython_在IPython中执行Python程序文件的示例
- 使用requireJS的shim參数,完毕jquery插件的载入
- sap.ui.layout.HorizontalLayout is not a constructor
- oracle 叠加代码写法,利用st_geometry进行图形叠加分析
- 怎么做手机的上下滑动_手机视频恢复怎么做?删除时间较久的找回方法
- 经常需要在开发中使用Excel COM,为简化使用写了这个类,感觉还是不太方便
- 【Flink】Flink如何传递JVM参数给JobManager和TaskManager
- python续行_python 控制台单行刷新,多行刷新
- LeetCode8. 字符串转换整数 (atoi)
- 常用的SEO工具都有哪些呢?5个SEO必备优化工具推荐
- UE4插件共享汇总大全
- 【达梦数据库DM8】DM8基本操作及DCA考试感悟分享
- 本题要求计算给定的一系列正整数中奇数的和。
- Linux系统增加新硬盘
- 【Dilated Conv】《Multi-Scale Context Aggregation by Dilated Convolutions》
- 初创企业融资PPT模板
热门文章
- JDBC连接池DBUtils使用
- 使用C语言操作InfluxDB
- 概率论中的公式解释(个人理解,非官方)- No1
- Coding theano under remote ubuntu server from local Mac (在本地mac机器上,写、跑、调试、看-远程ubuntu上的theano代码)...
- PTA是什么?BT-WIFI共存
- centos安装守护进程工具supervisor
- P2420 让我们异或吧 (树链剖分,异或前缀和)
- 01-bilibilidemo配置
- webApi项目中的问题
- 360再回应Citron财务造假 双方或将升到法律层面