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 ...
随机推荐
- Java 编程的动态性,第3部分: 应用反射--转载
在 上个月的文章中,我介绍了Java Reflection API,并简要地讲述了它的一些基本功能.我还仔细研究了反射的性能,并且在文章的最后给出了一些指导方针,告诉读者在一个应用程序中何时应该使用反 ...
- Mybatis插入语句useGeneratedKeys="true"的用法
<!-- 插入新的问题件 --> <!-- useGeneratedKeys="true"把新增加的主键赋值到自己定义的keyProperty(id)中 --&g ...
- Android 网络编程与通信协议
大多数的Android应用程序都会使用HTTP协议来发送和接收网络数据,而Android中主要提供了两种方式来进行HTTP操作, HttpURLConnection和HttpClient.这两种方式都 ...
- LSI MegaCli 命令使用2
#/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aALL 查raid级别#/opt/MegaRAID/MegaCli/MegaCli64 -AdpAll ...
- Could not reliably determine the server's fully qualified domain name
启动apache报错: [root@namenode1 ]# service httpd start Starting httpd: httpd: Could not reliably determi ...
- 第一个androidAPP项目总结—ListView的上拉和下拉
1.下拉刷新 需继承implements SwipeRefreshLayout.OnRefreshListener @Overridepublic void onRefresh() { new Wea ...
- ruby 知识点
$LOAD_PATH 执行 require 读取文件时搜索的目录名数组,也可以写作 $: 创建 URI 的时候可以直接这样 URI("http://www.dy2018.com/i/9751 ...
- mysql文件导入到数据库load data infile into table 的使用例子
load data infile "C:/Users/Administrator/Desktop/1.txt"into table 要一个已经存的表名 字段默认用制表符隔开 文件 ...
- 高放的c++学习笔记之类
类的基本思想是数据抽象和封装1.this 成员函数通过一个名为this的额外隐式参数来访问调用它的对象,当我们调用一个函数的时候,用请求该函数的对象的初始化this. 如果某个类的名字为sale,某个 ...
- 关于C++的变量和类的声明和定义
什么是变量?变量或者叫对象,是一个有具名的.可以供程序操作的存储空间.这里具名是指变量是有名字的,可供操作是指能进行加减乘除或者输入输出等操作,存储空间则是指有一块属于它的内存空间. 为了便于说明,标 ...