Flowery Trails |
Time Limit: 50000ms, Special Time Limit:125000ms, Memory Limit:65536KB |
Total submit users: 23, Accepted users: 21 |
Problem 13375 : No special judgement |
Problem description |
|
Input |
The first line of the input has two integers: P and T. P is the number of points of interest and T is the number of trails. Points are identified by integers, ranging from 0 to P-1. The entrance point is 0 and the highest peak is point P-1. |
Output |
The output has a single line with the extent of flowers (in metres) needed to cover both sides of the popular trails. |
Sample Input |
10 15 0 1 580 1 4 90 1 4 90 4 9 250 4 2 510 2 7 600 7 3 200 3 3 380 3 0 150 0 3 100 7 8 500 7 9 620 9 6 510 6 5 145 5 9 160 4 7 0 1 1 0 2 2 0 3 10 0 3 3 1 3 2 2 3 1 1 1 1 |
Sample Output |
3860 18 |
Problem Source |
HNU Contest 题意:把属于最短路上的所有边长相加*2就是答案。 #include<stdio.h> #include<queue> #include<string.h> using namespace std; const int N = 10005; #define INF 1<<30 #define ll long long struct EDG{ int to,next; ll cost; }edg[8000000] , node[5000000]; struct NODE{ int u; ll cost; friend bool operator<(NODE aa,NODE bb){ return aa.cost>bb.cost; } }; int eid,head[N]; ll disS[N],disT[N]; void init(int n){ eid=0; for(int i=0; i<=n; i++) disS[i]=disT[i]=INF; memset(head,-1,sizeof(head)); } void addEdg(int u,int v,ll cost) { edg[eid].to=v; edg[eid].next=head[u]; edg[eid].cost=cost; head[u]=eid++; edg[eid].to=u; edg[eid].next=head[v]; edg[eid].cost=cost; head[v]=eid++; } bool vist[N]; void dijkstar(int flag,int n) { priority_queue<NODE>q; NODE now,pre; memset(vist,0,sizeof(vist)); if(flag==0) now.u=0 , disS[0]=0; else now.u=n-1 , disT[n-1]=0; now.cost=0; q.push( now ); while( !q.empty()){ pre=q.top(); q.pop(); if(vist[pre.u])continue; vist[pre.u]=1; for(int i=head[pre.u]; i!=-1; i=edg[i].next){ int v=edg[i].to; if(flag==0){ if(disS[v]>pre.cost+edg[i].cost){ disS[v]=pre.cost+edg[i].cost; now.u=v; now.cost=disS[v]; q.push(now); } } else{ if(disT[v]>pre.cost+edg[i].cost){ disT[v]=pre.cost+edg[i].cost; now.u=v; now.cost=disT[v]; q.push(now); } } } } } int main() { int n,m , u,v; ll cost , ans; while(scanf("%d%d",&n,&m)>0) { init(n); for(int i=0; i<m; i++){ scanf("%d%d%lld",&u,&v,&cost); node[i].to=u; node[i].next=v; node[i].cost=cost; addEdg( u , v, cost); } dijkstar(0 , n); dijkstar(1 , n); ll mindis=disS[n-1] , ans=0; for(int i=0; i<m; i++) { u=node[i].to; v=node[i].next; if(disS[u]+node[i].cost+disT[v]==mindis||disS[v]+node[i].cost+disT[u]==mindis) ans+=node[i].cost; } printf("%lld\n",ans*2); } } |
版权声明:本文为博主原创文章,未经博主允许不得转载。
HNU 13375 Flowery Trails (最短路)
原文地址:http://blog.csdn.net/u010372095/article/details/47378403