http://www.lydsy.com/JudgeOnline/problem.php?id=3538

题意不要理解错QAQ,是说当前边(u,v)且u到n的最短距离中包含这条边,那么这条边就不警告。

那么我们反向spfa两次,然后再正向spfa就行了

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=10006, M=5*N, oo=~0u>>2;
int n, ihead[N], d[3][N], m, q[N], front, tail, vis[N], cnt, tot, P[M], Q[M], U[M], V[M];
struct ED { int to, w, next; }e[M];
void add(int u, int v) {
e[++cnt].next=ihead[u]; ihead[u]=cnt; e[cnt].to=v;
} void spfa(int s, int *d) {
for1(i, 1, n) d[i]=oo;
front=tail=0;
vis[s]=1; q[tail++]=s; d[s]=0;
int v;
while(front!=tail) {
int u=q[front++]; if(front==N) front=0; vis[u]=0;
for(int i=ihead[u]; i; i=e[i].next) if(d[v=e[i].to]>d[u]+e[i].w) {
d[v]=d[u]+e[i].w;
if(!vis[v]) {
vis[v]=1;
q[tail++]=v; if(tail==N) tail=0;
}
}
}
} int main() {
read(n); read(m);
for1(i, 1, m) {
int u=getint(), v=getint();
add(v, u);
P[i]=getint(); Q[i]=getint();
U[i]=u; V[i]=v;
}
for1(i, 1, cnt) e[i].w=P[i];
spfa(n, d[0]);
for1(i, 1, cnt) e[i].w=Q[i];
spfa(n, d[1]);
CC(ihead, 0); cnt=0;
for1(i, 1, m) {
int u=U[i], v=V[i];
add(u, v);
e[i].w=2;
if(d[0][u]==d[0][v]+P[i]) --e[i].w;
if(d[1][u]==d[1][v]+Q[i]) --e[i].w;
}
spfa(1, d[2]);
if(d[2][n]==oo) d[2][n]=-1;
print(d[2][n]);
return 0;
}

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

最新文章

  1. 将一张表的数据,拷贝到另一张表中sql
  2. C++ 系列:继承
  3. 587A
  4. 友盟iOS推送配置(从真机调试到推送)
  5. bzoj 1391 [Ceoi2008]order(最小割)
  6. Apache Ranger对HDFS的访问权限控制的原理分析(一)
  7. **********MySql查询方法重要**********
  8. 嵌入式Linux引导过程之1.5——从BootRom到Xloader
  9. Java基础学习(四)-- 接口、集合框架、Collection、泛型详解
  10. mapreduce map 的个数
  11. Beta冲刺 4
  12. pache tomcat慢速HTTP拒绝服务攻击安全问题解决办法
  13. Python 递归的练习
  14. SqlBulkCopy批量插入数据神器
  15. OpenStack 安装:keystone服务
  16. OS + CentOS 7 / centos 7 / VirtualBox /vegrant
  17. Git服务器,仓库的hook监控
  18. OCM_第十二天课程:Section6 &mdash;》数据库性能调优_ 资源管理器/执行计划
  19. bootstrap的学习总结
  20. YAML描述与Python的对应关系

热门文章

  1. Solidworks如何设置零件材料,如何评估零件质量
  2. java中的Annotation
  3. js中字符串转换为数字
  4. WebDriver API——第4部分Alerts
  5. RGB和HSL色彩的相互转换
  6. FAT AP v200R005 配置二层透明模式(web&amp;命令行,开局)
  7. 对oracle数字类型的研究
  8. eclipse项目 乱码
  9. unity3d世界坐标系和本地坐标系
  10. C语言控制台打印3D爱心图案