BZOJ3538: [Usaco2014 Open]Dueling GPS
3538: [Usaco2014 Open]Dueling GPS
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 59 Solved: 36
[Submit][Status]
Description
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.
Input
* Line 1: The integers N and M. Line i describes road i with four integers: A_i B_i P_i Q_i.
Output
* Line 1: The minimum total number of complaints FJ can receive if he routes himself from his house to the farm optimally.
Sample Input
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
INPUT DETAILS: 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.
Sample Output
OUTPUT DETAILS: 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.
HINT
Source
题解:
麻烦的sb题。。。来回搞几次spfa就行了
代码:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define inf 0x7fffffff
#define MAXN 100001
using namespace std; 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;
} struct edge {
int to, next, v1, v2;
} e[MAXN], d[MAXN];
int n, m, cnt, ans, u[MAXN], v[MAXN], w1[MAXN], w2[MAXN], d1[], d2[], dis[], head[], h[]; void ins(int u, int v, int w1, int w2) {
e[++cnt] = (edge){v, head[u], w1, w2};
head[u] = cnt;
} void spfa1() {
int q[MAXN], t = , w = ;
bool inq[];
memset(inq, , sizeof (inq));
memset(d1, , sizeof (d1));
d1[n] = ;
q[] = n;
inq[n] = ;
while (t <= w) {
int now = q[t++];
for (int i = head[now]; i; i = e[i].next) {
if (d1[now] + e[i].v1 < d1[e[i].to]) {
d1[e[i].to] = d1[now] + e[i].v1;
if (!inq[e[i].to]) {
q[++w] = e[i].to;
inq[e[i].to] = ;
}
}
}
inq[now] = ;
}
} void spfa2() {
int q[MAXN], t = , w = ;
bool inq[];
memset(inq, , sizeof (inq));
memset(d2, , sizeof (d2));
d2[n] = ;
q[] = n;
inq[n] = ;
while (t <= w) {
int now = q[t++];
for (int i = head[now]; i; i = e[i].next) {
if (d2[now] + e[i].v2 < d2[e[i].to]) {
d2[e[i].to] = d2[now] + e[i].v2;
if (!inq[e[i].to]) {
q[++w] = e[i].to;
inq[e[i].to] = ;
}
}
}
inq[now] = ;
}
} void spfa3() {
int q[MAXN], t = , w = ;
bool inq[];
memset(inq, , sizeof (inq));
memset(dis, , sizeof (dis));
dis[] = ;
q[] = ;
inq[] = ;
while (t <= w) {
int now = q[t++];
for (int i = h[now]; i; i = d[i].next) {
if (dis[now] + d[i].v1 < dis[d[i].to]) {
dis[d[i].to] = dis[now] + d[i].v1;
if (!inq[d[i].to]) {
q[++w] = d[i].to;
inq[e[i].to] = ;
}
}
}
inq[now] = ;
}
} int main() {
n = read();
m = read();
for (int i = ; i <= m; i++) {
u[i] = read();
v[i] = read();
w1[i] = read();
w2[i] = read();
ins(v[i], u[i], w1[i], w2[i]);
}
spfa1();
spfa2();
for (int i = ; i <= m; i++) {
d[i].to = v[i];
d[i].next = h[u[i]];
h[u[i]] = i;
if (d1[v[i]] + w1[i] > d1[u[i]])d[i].v1++;
if (d2[v[i]] + w2[i] > d2[u[i]])d[i].v1++;
}
spfa3();
printf("%d", dis[n]);
return ;
}
BZOJ3538: [Usaco2014 Open]Dueling GPS的更多相关文章
- 【BZOJ】3538: [Usaco2014 Open]Dueling GPS(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=3538 题意不要理解错QAQ,是说当前边(u,v)且u到n的最短距离中包含这条边,那么这条边就不警告. ...
- BZOJ 3538 == 洛谷 P3106 [USACO14OPEN]GPS的决斗Dueling GPS's
P3106 [USACO14OPEN]GPS的决斗Dueling GPS's 题目描述 Farmer John has recently purchased a new car online, but ...
- USACO Dueling GPS's
洛谷 P3106 [USACO14OPEN]GPS的决斗Dueling GPS's 洛谷传送门 JDOJ 2424: USACO 2014 Open Silver 2.Dueling GPSs JDO ...
- Luogu P3106 [USACO14OPEN]GPS的决斗Dueling GPS's(最短路)
P3106 [USACO14OPEN]GPS的决斗Dueling GPS's 题意 题目描述 Farmer John has recently purchased a new car online, ...
- [USACO14OPEN] Dueling GPS's[最短路建模]
题目描述 Farmer John has recently purchased a new car online, but in his haste he accidentally clicked t ...
- 洛谷 3106 [USACO14OPEN]GPS的决斗Dueling GPS's 3720 [AHOI2017初中组]guide
[题解] 这两道题是完全一样的. 思路其实很简单,对于两种边权分别建反向图跑dijkstra. 如果某条边在某一种边权的图中不是最短路上的边,就把它的cnt加上1.(这样每条边的cnt是0或1或2,代 ...
- [USACO14OPEN]GPS的决斗Dueling GPS's
题目概况 题目描述 给你一个\(N\)个点的有向图,可能有重边. 有两个\(GPS\)定位系统,分别认为经过边\(i\)的时间为\(P_i\),和\(Q_i\). 每走一条边的时候,如果一个系统认为走 ...
- USACO 2014 US Open Dueling GPS's /// SPFA
题目大意: 给定n个点m条边的有向图 有两个GPS 分别认为 A[i]到B[i] 的一条边的花费是P[i].Q[i] 当当前走的边不是GPS认为的最短路上的边就会被警告 即两个GPS都不认为是最短路上 ...
- 2018.07.22 洛谷P3106 GPS的决斗Dueling GPS's(最短路)
传送门 图论模拟题. 这题直接写3个(可以压成一个)spfa" role="presentation" style="position: relative;&q ...
随机推荐
- angular 按需加载
angular.module('app',[]) .controller('ctrl',function ($http,$scope){ //ctrl控制器,名称作用的范围 html中ng-cont ...
- jvm之内存分配与回收策略
1.java堆中各代分布 (1)Young:主要是用来存放新生的对象. (2)Old:主要存放应用程序中生命周期长的内存对象. (3)Permanent:是指内存的永久保存区域,主要存放Class和M ...
- 【ArcGIS 10.2新特性】Geodatabase 10.2 常见问题
地理数据库技术一直以来都是ArcGIS的基础技术.为充分使用ArcGIS的全部功能则需要把数据存储在Geodatabase当中.Geodatabase是一个综合性的信息模型,它可以支持存储几乎任意类型 ...
- 使用glob()查找文件(转)
大部分PHP函数的函数名从字面上都可以理解其用途,但是当你看到 glob() 的时候,你也许并不知道这是用来做什么的,其实glob()和scandir() 一样,可以用来查找文件,请看下面的用法: ...
- tomcat结合nginx使用 基础教程
相信很多人都听过nginx,这个小巧的东西慢慢地在吞食apache和IIS的份额.那究竟它有什么作用呢?可能很多人未必了解. 说到反向代理,可能很多人都听说,但具体什么是反向代理,很多人估计就不清楚了 ...
- Windows下将硬盘由MBR转为GPT
打开命令提示符,输入 diskpart 进入diskpart提示符.Win7/Vista用户可以直接在开始菜单的搜索框中输入diskpart回车即可打开diskpart提示符. 在diskpart提示 ...
- Windows离线安装.NET3.X
Windows离线安装.NET3.X 当我们在Windows上安装软件的时候,总是会提示需要安装.NET3.X.而大多数人们选择在线安装,这样会很慢,不少人想到了离线安装的方式.其是只要你的电脑是Wi ...
- javascript基础之javascript的存在形式和js代码块在页面中的存放位置
1.存在形式 文件 如: <script src='js/jc.js'></script> 前页面 <script type='text/javascript'>a ...
- Eclipse下Maven插件配置
要做一个基于C/S架构的汽车租赁系统,由于在实习期间接触过一些Java和SpringMVC,Spring,Hibernate的东西,所以决定使用这个框架组合来完成这个项目. 首先是Maven的配置,为 ...
- java实现字符串反转(原作有点错误,需要看下评论)
http://blog.csdn.net/shenshen123jun/article/details/9104025