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 ;
}

终于可以骄傲的删掉那篇 待解决

最新文章

  1. Oracle 把秒转成时分秒格式(hh24:mm:ss);检测字符串是否是数字;字符串转换为数字
  2. IE11 iframe alternative
  3. poj 1847 最短路简单题,dijkstra
  4. linux apache 自动监护脚本
  5. C# 递归程序 获取某个节点下的全部子节点
  6. sqlite3简单使用
  7. Java基础知识强化72:正则表达式之判断功能(手机号码判断 和 校验邮箱)
  8. hdu5358 First One(尺取法)
  9. JAVA-反射-getGenericSuperclass()
  10. Windows下Nginx的启动、停止等基本命令
  11. 配置maven项目的开发时的默认jdk版本
  12. hive函数--编码解码
  13. Docker registry垃圾回收
  14. 从小白到区块链工程师:第一阶段:Go语言环境的搭建(1)
  15. python day27--常用模块 time,random,os,序列化
  16. php框架:Flight 简介
  17. arcgis python添加几何属性
  18. [py][mx]django实现课程机构排名
  19. 学习blus老师js(4)--DOM
  20. 【ocp-12c】最新Oracle OCP-071考试题库(46题)

热门文章

  1. MySQL数据库的下载安装
  2. 六、MySQL 删除数据库
  3. linux通配符知识
  4. 前段ztree 树状插件
  5. 查询集 QuerySet和管理器Manager
  6. 多线程并发测试(apache ad)
  7. Thread 小总结
  8. request_resource
  9. cf975d Ghosts
  10. 2018安恒杯11月月赛 MISC