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.

给你一个N个点的有向图,可能有重边.
有两个GPS定位系统,分别认为经过边i的时间为Pi,和Qi.
每走一条边的时候,如果一个系统认为走的这条边不是它认为的最短路,就会受到警告一次T T
两个系统是分开警告的,就是说当走的这条边都不在两个系统认为的最短路范围内,就会受到2次警告.
求一种方案,1àn,最少需要受到多少次警告.

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

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

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

1
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

Silver By liyizhen2

题解:

麻烦的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的更多相关文章

  1. 【BZOJ】3538: [Usaco2014 Open]Dueling GPS(spfa)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3538 题意不要理解错QAQ,是说当前边(u,v)且u到n的最短距离中包含这条边,那么这条边就不警告. ...

  2. BZOJ 3538 == 洛谷 P3106 [USACO14OPEN]GPS的决斗Dueling GPS's

    P3106 [USACO14OPEN]GPS的决斗Dueling GPS's 题目描述 Farmer John has recently purchased a new car online, but ...

  3. USACO Dueling GPS's

    洛谷 P3106 [USACO14OPEN]GPS的决斗Dueling GPS's 洛谷传送门 JDOJ 2424: USACO 2014 Open Silver 2.Dueling GPSs JDO ...

  4. Luogu P3106 [USACO14OPEN]GPS的决斗Dueling GPS's(最短路)

    P3106 [USACO14OPEN]GPS的决斗Dueling GPS's 题意 题目描述 Farmer John has recently purchased a new car online, ...

  5. [USACO14OPEN] Dueling GPS's[最短路建模]

    题目描述 Farmer John has recently purchased a new car online, but in his haste he accidentally clicked t ...

  6. 洛谷 3106 [USACO14OPEN]GPS的决斗Dueling GPS's 3720 [AHOI2017初中组]guide

    [题解] 这两道题是完全一样的. 思路其实很简单,对于两种边权分别建反向图跑dijkstra. 如果某条边在某一种边权的图中不是最短路上的边,就把它的cnt加上1.(这样每条边的cnt是0或1或2,代 ...

  7. [USACO14OPEN]GPS的决斗Dueling GPS's

    题目概况 题目描述 给你一个\(N\)个点的有向图,可能有重边. 有两个\(GPS\)定位系统,分别认为经过边\(i\)的时间为\(P_i\),和\(Q_i\). 每走一条边的时候,如果一个系统认为走 ...

  8. USACO 2014 US Open Dueling GPS's /// SPFA

    题目大意: 给定n个点m条边的有向图 有两个GPS 分别认为 A[i]到B[i] 的一条边的花费是P[i].Q[i] 当当前走的边不是GPS认为的最短路上的边就会被警告 即两个GPS都不认为是最短路上 ...

  9. 2018.07.22 洛谷P3106 GPS的决斗Dueling GPS's(最短路)

    传送门 图论模拟题. 这题直接写3个(可以压成一个)spfa" role="presentation" style="position: relative;&q ...

随机推荐

  1. Android ArrayAdapter MultiAutoCompleteTextView

    MultiAutoCompleteTextView 继承自AutoCompleteTextView,它和AutoCompleteTextView不同的就是能处理多个输入字段,如发送短信界面的联系人列表 ...

  2. Cobar是提供关系型数据库(MySQL)分布式服务的中间件

    简介 Cobar是提供关系型数据库(MySQL)分布式服务的中间件,它可以让传统的数据库得到良好的线性扩展,并看上去还是一个数据库,对应用保持透明. 产品在阿里巴巴稳定运行3年以上. 接管了3000+ ...

  3. Java基础知识强化92:日期工具类的编写和测试案例

    1. DateUtil.java,代码如下: package cn.itcast_04; import java.text.ParseException; import java.text.Simpl ...

  4. css05文本,文字属性

    1.创建一个html页面 <!DOCTYPE html> <html> <head lang="en"> <meta charset=&q ...

  5. web03--session

    1.创建session1.jsp <body> <form action="session2.jsp" method="post"> & ...

  6. css基础回顾-定位:position

    w3school 对position定义和说明是: 定义和用法: position 属性规定元素的定位类型. 说明: 这个属性定义建立元素布局所用的定位机制.任何元素都可以定位,不过绝对或固定元素会生 ...

  7. CSS3 3D转换

    CSS3允许你使用3D转换来对元素进行格式化. 3D转换方法: rotateX() rotateY() 浏览器支持 属性 浏览器支持 transform           IE10和Firefox支 ...

  8. android中控件的使用

    http://www.cnblogs.com/linjiqin/category/284058.html

  9. 关于Adobe Flash 11.3 引起的火狐使用问题

    Adobe Flash 更新到11.3之后,为火狐引入Flash沙盒安全模式,但同时,又造成了部分兼容性问题,导致 Windows vista及 Windows 7上部分火狐崩溃,并致使一些使用Fla ...

  10. C#操作MYSQL遇到0000-00-00日期报错的原因

    今天在做一个C#连接MYSQL数据库,并读取数据库的内容,遇到了0000-00-00日期转换报错:unable to convert MySQL date/time value to System.D ...