BZOJ 3538 == 洛谷 P3106 [USACO14OPEN]GPS的决斗Dueling GPS's
P3106 [USACO14OPEN]GPS的决斗Dueling GPS's
题目描述
Farmer John has recently purchased a new car online, but in his haste he accidentally clicked the "Submit" button twice when selecting extra features for the car, and as a result the car ended up equipped with two GPS navigation systems! Even worse, the two systems often make conflicting decisions about the route that FJ should take.
The map of the region in which FJ lives consists of N intersections (2 <= N <= 10,000) and M directional roads (1 <= M <= 50,000). Road i connects intersections A_i (1 <= A_i <= N) and B_i (1 <= B_i <= N). Multiple roads could connect the same pair of intersections, and a bi-directional road (one permitting two-way travel) is represented by two separate directional roads in opposite orientations. FJ's house is located at intersection 1, and his farm is located at intersection N. It is possible to reach the farm from his house by traveling along a series of directional roads.
Both GPS units are using the same underlying map as described above; however, they have different notions for the travel time along each road. Road i takes P_i units of time to traverse according to the first GPS unit, and Q_i units of time to traverse according to the second unit (each travel time is an integer in the range 1..100,000).
FJ wants to travel from his house to the farm. However, each GPS unit complains loudly any time FJ follows a road (say, from intersection X to intersection Y) that the GPS unit believes not to be part of a shortest route from X to the farm (it is even possible that both GPS units can complain, if FJ takes a road that neither unit likes).
Please help FJ determine the minimum possible number of total complaints he can receive if he chooses his route appropriately. If both GPS units complain when FJ follows a road, this counts as +2 towards the total.
给你一个N个点的有向图,可能有重边.
有两个GPS定位系统,分别认为经过边i的时间为Pi,和Qi.
每走一条边的时候,如果一个系统认为走的这条边不是它认为的最短路,就会受到警告一次T T
两个系统是分开警告的,就是说当走的这条边都不在两个系统认为的最短路范围内,就会受到2次警告.
如果边(u,v)不在u到n的最短路径上,这条边就受到一次警告,求从1到n最少受到多少次警告。
输入输出格式
输入格式:
- Line 1: The integers N and M.
Line i describes road i with four integers: A_i B_i P_i Q_i.
输出格式:
- Line 1: The minimum total number of complaints FJ can receive if he routes himself from his house to the farm optimally.
输入输出样例
5 7
3 4 7 1
1 3 2 20
1 4 17 18
4 5 25 3
1 2 10 1
3 5 4 14
2 4 6 5
1
说明
There are 5 intersections and 7 directional roads. The first road connects from intersection 3 to intersection 4; the first GPS thinks this road takes 7 units of time to traverse, and the second GPS thinks it takes 1 unit of time, etc.
If FJ follows the path 1 -> 2 -> 4 -> 5, then the first GPS complains on the 1 -> 2 road (it would prefer the 1 -> 3 road instead). However, for the rest of the route 2 -> 4 -> 5, both GPSs are happy, since this is a shortest route from 2 to 5 according to each GPS.
啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊!!!!!!!!!!!!!!
挺了四天的题目终于过了~~~~~~~~~~~~
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
using namespace std;
#define maxn 100010
#define MAXN 100010
#define mse(a,x) memset(a,x,sizeof(a));
queue<int>q;
int n,m,tot,ans,u[MAXN],v[MAXN],value1[MAXN];
int value2[MAXN],dis_1[],dis_2[];
int dis[maxn],head[maxn],link[maxn];
struct Edge{
int to,next,w_one,w_two;
}e[maxn],ee[maxn];
inline int read(){
int x=,f=;
char ch=getchar();
while(ch<'' || ch >''){
if (ch == '-')f=-;
ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
void SPFA_First(){
bool exist[maxn];
while(!q.empty())q.pop();
mse(dis_1,0x3f);mse(exist,false);
dis_1[n]=;q.push(n);exist[n]=true;
while(!q.empty()){
int p=q.front();q.pop();exist[p]=false;
for(int i=head[p];i;i=e[i].next){
int v=e[i].to;
if(dis_1[v]>dis_1[p]+e[i].w_one){
dis_1[v]=dis_1[p]+e[i].w_one;
if(!exist[v]){
q.push(v);exist[v]=true;
}
}
}
}
}
void SPFA_Second(){
bool exist[maxn];
while(!q.empty())q.pop();
mse(dis_2,0x3f);mse(exist,false);
dis_2[n]=;q.push(n);exist[n]=true;
while(!q.empty()){
int p=q.front();q.pop();exist[p]=false;
for(int i=head[p];i;i=e[i].next){
int v=e[i].to;
if(dis_2[v]>dis_2[p]+e[i].w_two){
dis_2[v]=dis_2[p]+e[i].w_two;
if(!exist[v]){
q.push(v);exist[v]=true;
}
}
}
}
} void Add_Edge(int u,int v,int w1,int w2){
e[++tot].to=v;e[tot].w_one=w1;e[tot].w_two=w2;
e[tot].next=head[u];head[u]=tot;
}
void SPFA_Third(){
bool exist[maxn];
while(!q.empty())q.pop();
mse(exist,false);mse(dis,0x3f);
dis[]=;exist[]=;q.push();
while(!q.empty()){
int now=q.front();q.pop();exist[now]=false;
for (int i=link[now];i;i=ee[i].next) {
if (dis[now]+ee[i].w_one<dis[ee[i].to]){
dis[ee[i].to]=dis[now]+ee[i].w_one;
if (!exist[ee[i].to]) {
q.push(ee[i].to);
exist[e[i].to]=;
}
}
}
}
}
int main()
{
n=read();m=read();
for(int i=;i<=m;i++){
u[i]=read();v[i]=read();
value1[i]=read();value2[i]=read();
Add_Edge(v[i],u[i],value1[i],value2[i]);
// 注意这里是 建的 反边
}
SPFA_First();
SPFA_Second();
for(int i=;i<=m;i++){
ee[i].to=v[i];ee[i].next=link[u[i]];
link[u[i]]=i;
if(dis_1[v[i]]+value1[i]>dis_1[u[i]])
ee[i].w_one++;
if(dis_2[v[i]]+value2[i]>dis_2[u[i]])
ee[i].w_one++;
}
SPFA_Third();
printf("%d",dis[n]);
return ;
}
终于可以骄傲的删掉那篇 待解决
BZOJ 3538 == 洛谷 P3106 [USACO14OPEN]GPS的决斗Dueling GPS's的更多相关文章
- Luogu P3106 [USACO14OPEN]GPS的决斗Dueling GPS's(最短路)
P3106 [USACO14OPEN]GPS的决斗Dueling GPS's 题意 题目描述 Farmer John has recently purchased a new car online, ...
- 洛谷 3106 [USACO14OPEN]GPS的决斗Dueling GPS's 3720 [AHOI2017初中组]guide
[题解] 这两道题是完全一样的. 思路其实很简单,对于两种边权分别建反向图跑dijkstra. 如果某条边在某一种边权的图中不是最短路上的边,就把它的cnt加上1.(这样每条边的cnt是0或1或2,代 ...
- 2018.07.22 洛谷P3106 GPS的决斗Dueling GPS's(最短路)
传送门 图论模拟题. 这题直接写3个(可以压成一个)spfa" role="presentation" style="position: relative;&q ...
- [USACO14OPEN]GPS的决斗Dueling GPS's
题目概况 题目描述 给你一个\(N\)个点的有向图,可能有重边. 有两个\(GPS\)定位系统,分别认为经过边\(i\)的时间为\(P_i\),和\(Q_i\). 每走一条边的时候,如果一个系统认为走 ...
- [BZOJ 3039&洛谷P4147]玉蟾宫 题解(单调栈)
[BZOJ 3039&洛谷P4147]玉蟾宫 Description 有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地. ...
- bzoj 4816: 洛谷 P3704: [SDOI2017]数字表格
洛谷很早以前就写过了,今天交到bzoj发现TLE了. 检查了一下发现自己复杂度是错的. 题目传送门:洛谷P3704. 题意简述: 求 \(\prod_{i=1}^{N}\prod_{j=1}^{M}F ...
- bzoj 1014: 洛谷 P4036: [JSOI2008]火星人
题目传送门:洛谷P4036. 题意简述: 有一个字符串,支持插入字符,修改字符. 每次需要查询两个后缀的LCP长度. 最终字符串长度\(\le 100,\!000\),修改和询问的总个数\(\le 1 ...
- bzoj 3680(洛谷1337) 吊打XXX——模拟退火
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3680 https://www.luogu.org/problemnew/show/P1337 ...
- bzoj 4592(洛谷 4344) [Shoi2015]脑洞治疗仪——线段树上二分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4592 1操作就是用线段树来二分找到第一个有 k 个0的位置. 在洛谷上A了,与暴力和网上题解 ...
随机推荐
- nginx Keepalived高可用集群
一.Keepalived高可用 1.简介 Keepalived软件起初是专为LvS负载均衡软件设计的,用来管理并监控LVS集群系统中各个服务节点的状态,后来又加入了可以实现高可用的VRRP功能.因此, ...
- HTML5/CSS3 第二章页面组件
页面组件 1 元素的尺寸/边框/背景 1.1 css尺寸相关属性 height 高度 min-height 最小高度 max-height 最大高度 width 宽度 min-width 最小宽度 m ...
- 【CSS】非常简单的css实现div悬浮页面底部
<div id="demo_div"></div> <style> #demo_div{ left:; position: fixed; bot ...
- Redis之String类型操作
接口IRedisDaoStr: package com.net.test.redis.base.dao; import java.util.List; import java.util.Map; /* ...
- Tame Me【驯服我】
Tame Me “Good morning,” said the fox. 早上好,狐狸说 “Good morming,” the little prince responded politely,a ...
- Scrapy框架中选择器的用法【转】
Python爬虫从入门到放弃(十四)之 Scrapy框架中选择器的用法 请给作者点赞 --> 原文链接 Scrapy提取数据有自己的一套机制,被称作选择器(selectors),通过特定的Xpa ...
- OpenCV学习笔记(六) 滤波器 形态学操作(腐蚀、膨胀等)
转自:OpenCV 教程 另附:计算机视觉:算法与应用(2012),Learning OpenCV(2009) 平滑图像:滤波器 平滑 也称 模糊, 是一项简单且使用频率很高的图像处理方法.平滑处理的 ...
- 如何拿到半数面试公司Offer——我的Python求职之路(转)
从八月底开始找工作,短短的一星期多一些,面试了9家公司,拿到5份Offer,可能是因为我所面试的公司都是些创业性的公司吧,不过还是感触良多,因为学习Python的时间还很短,没想到还算比较容易的找到了 ...
- 如何排查Java内存泄漏?看完我给跪了!
没有经验的程序员经常认为Java的自动垃圾回收完全使他们免于担心内存管理.这是一个常见的误解:虽然垃圾收集器做得很好,但即使是最好的程序员也完全有可能成为严重破坏内存泄漏的牺牲品.让我解释一下. 当不 ...
- 洛谷P1067 多项式输出
题目链接:https://www.luogu.org/problemnew/show/P1067 这是一个纯模拟的小怪但是需要注意一些小细节: 1.首项为正没有+号. 2.所有项系数如果是一的话就省略 ...