【洛谷P3106】[USACO14OPEN]GPS的决斗Dueling GPS's
生活随笔
收集整理的這篇文章主要介紹了
【洛谷P3106】[USACO14OPEN]GPS的决斗Dueling GPS's
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目描述
給你一個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.
代碼
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; const int maxn=50000+5; inline void read(int &x){x=0; char ch=getchar();while(ch<'0'||ch>'9') ch=getchar();while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} } int n,m,tot,u[maxn],v[maxn],p[maxn],q[maxn]; int head[maxn],dis[4][maxn]; bool inq[maxn]; queue<int>Q; struct node{int next,to,c[4]; }e[maxn<<1]; inline void ins(int from,int to,int c1,int c2,int c3){e[++tot].next=head[from];e[tot].to=to; e[tot].c[1]=c1; e[tot].c[2]=c2; e[tot].c[3]=c3;head[from]=tot; } void spfa(int x,int k){Q.push(x); dis[k][x]=0; inq[x]=1;do{int u=Q.front(); Q.pop(); inq[u]=0;for(int i=head[u];i;i=e[i].next)if(dis[k][e[i].to]>dis[k][u]+e[i].c[k]){dis[k][e[i].to]=dis[k][u]+e[i].c[k];if(!inq[e[i].to]) Q.push(e[i].to),inq[e[i].to]=1;}}while(!Q.empty()); } int main(){read(n);read(m);for(int i=1;i<=m;++i){read(u[i]);read(v[i]);read(p[i]);read(q[i]);ins(v[i],u[i],p[i],q[i],0);}memset(dis,0x3f,sizeof(dis));spfa(n,1); spfa(n,2);tot=0; memset(head,0,sizeof(head));for(int i=1;i<=m;++i){int w=2;if(dis[1][u[i]]-dis[1][v[i]]==p[i]) --w;if(dis[2][u[i]]-dis[2][v[i]]==q[i]) --w;ins(u[i],v[i],0,0,w);}spfa(1,3);printf("%d\n",dis[3][n]);return 0; }?
轉載于:https://www.cnblogs.com/huihao/p/7757991.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的【洛谷P3106】[USACO14OPEN]GPS的决斗Dueling GPS's的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CSS 画一个八卦
- 下一篇: Rancher的简单部署和使用