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.

输入输出样例

输入样例#1:

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:

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.

啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊!!!!!!!!!!!!!!

挺了四天的题目终于过了~~~~~~~~~~~~

题意:
给你一个N个点的有向图,设定初始位置为1,结束位置为n。有两个GPS定位系统,分别认为经过边i的时间为Pi,和Qi.每走一条边的时候,如果一个系统认为走的这条边不是它认为的最短路,就会受到警告一次。如果走的这条边都不在两个系统认为的最短路范围内,就会受到2次警告。求最少需要受到多少次警告。n≤10000,边数≤50000
 #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的更多相关文章

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

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

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

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

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

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

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

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

  5. [BZOJ 3039&洛谷P4147]玉蟾宫 题解(单调栈)

    [BZOJ 3039&洛谷P4147]玉蟾宫 Description 有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地. ...

  6. bzoj 4816: 洛谷 P3704: [SDOI2017]数字表格

    洛谷很早以前就写过了,今天交到bzoj发现TLE了. 检查了一下发现自己复杂度是错的. 题目传送门:洛谷P3704. 题意简述: 求 \(\prod_{i=1}^{N}\prod_{j=1}^{M}F ...

  7. bzoj 1014: 洛谷 P4036: [JSOI2008]火星人

    题目传送门:洛谷P4036. 题意简述: 有一个字符串,支持插入字符,修改字符. 每次需要查询两个后缀的LCP长度. 最终字符串长度\(\le 100,\!000\),修改和询问的总个数\(\le 1 ...

  8. bzoj 3680(洛谷1337) 吊打XXX——模拟退火

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3680 https://www.luogu.org/problemnew/show/P1337 ...

  9. bzoj 4592(洛谷 4344) [Shoi2015]脑洞治疗仪——线段树上二分

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4592 1操作就是用线段树来二分找到第一个有 k 个0的位置. 在洛谷上A了,与暴力和网上题解 ...

随机推荐

  1. JVM垃圾回收--年轻代、年老点和持久代(转)

      关键字约定 Young generation –>新生代 Tenured / Old Generation –>老年代 Perm Area –>永久代 年轻代: 所有新生成的对象 ...

  2. P1101 单词方阵

    题目描述 给一 n \times nn×n 的字母方阵,内可能蕴含多个"yizhong"单词.单词在方阵中是沿着同一方向连续摆放的.摆放可沿着 88 个方向的任一方向,同一单词摆放 ...

  3. springMVC中接收数组参数

    方式一. 后台:public ResultBean queryItemRulesByItemIds(int userId, int[] itemIds) 方式二.

  4. 1497: [NOI2006]最大获利(最大权闭合子图)

    1497: [NOI2006]最大获利 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 5503  Solved: 2673 Description 新的技 ...

  5. Linux设置运行core dump

    系统配置vim /etc/sysctl.conf kernel.core_uses_pid = kernel.core_pattern = %e-core-%p-%t sysctl -p检查有没有生效 ...

  6. 非常全面的vim配置文件

    1.mac下vim全局配置目录 /usr/share/vim/vimrc 一般不对此文件做修改,在用户目录下创建自定义配置,目录为: /Users/xxxxx cd ~ 2自定义vim配置 配置功能: ...

  7. 学习python3之路的第一个小代码-----------9*9乘法表

    这个编写的简单,用两个循环迭代就行.下面就是我写的编码以及输出的结果 1 #!/usr/bin/env python 2 # encoding: utf-8 3 4 i = 1 5 6 while i ...

  8. python拼接

    拼接: name=zhuhuan age=23 salary=333 info=''' ----- info of %s----- age:%s name:%s salary:%s %(name,ag ...

  9. Android数据储存之File

    openFileOutStream 和 openFileInStream FileInputStream fileInputStream = openFileInput(name);  打开应用下文件 ...

  10. 【转】behave行为树学习使用第一天

    最近在学习使用行为树做AI,决定把学到的贡献出来,抛砖引玉,希望可以认识到更多大牛 -- 首先我们了解下什么是行为树和为什么要使用行为树.   在我们项目中如果需要做一个AI敌人,比如做一个手游 某民 ...