标签:pair int 思路 compute 其他 eve ace priority 分享
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 11612 | Accepted: 5550 |
Description
Input
Output
Sample Input
4 2 1 1 3 10 2 4 20 2 3 3
Sample Output
27
Hint
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<map> #include<queue> #include<stack> #include<vector> #include<set> using namespace std; typedef pair<int,int> P; typedef long long ll; const int maxn=1e5+100,inf=0x3f3f3f3f,mod=1e9+7; const ll INF=1e13+7; struct edge { int from,to; int cost; }; int cou=0; edge es[maxn]; vector<edge>G[maxn]; int used[maxn]; priority_queue<P,vector<P>,greater<P> >que; void addedge(int u,int v,int w) { cou++; edge e; e.from=u,e.to=v,e.cost=w; es[cou].from=u,es[cou].to=v,es[cou].cost=w; G[u].push_back(e); } int n,ml,md; int al[maxn],bl[maxn],dl[maxn]; int ad[maxn],bd[maxn],dd[maxn]; int d[maxn]; void ford() { for(int i=1; i<=n; i++) d[i]=inf; d[1]=0; for(int t=1; t<n; t++) { for(int i=1; i<n; i++) if(d[i+1]<inf) d[i]=min(d[i],d[i+1]); for(int i=1; i<=ml; i++) if(d[al[i]]<inf) d[bl[i]]=min(d[bl[i]],d[al[i]]+dl[i]); for(int i=1; i<=md; i++) if(d[bd[i]]<inf) d[ad[i]]=min(d[ad[i]],d[bd[i]]-dd[i]); } if(d[1]<0) cout<<-1<<endl; else if(d[n]>=inf) cout<<-2<<endl; else cout<<d[n]<<endl; } int main() { int a,b,d; scanf("%d%d%d",&n,&ml,&md); for(int i=1; i<n; i++) addedge(i+1,i,0); for(int i=1; i<=ml; i++) scanf("%d%d%d",&al[i],&bl[i],&dl[i]); for(int i=1; i<=md; i++) scanf("%d%d%d",&ad[i],&bd[i],&dd[i]); ford(); return 0; } /* 4 3 0 1 3 10 2 4 20 2 3 3 */
标签:pair int 思路 compute 其他 eve ace priority 分享
原文地址:http://www.cnblogs.com/GeekZRF/p/7069514.html