标签:back family next break 长度 using bsp class min
3 2 1 2 5 6 2 3 4 5 1 3 0 0
9 11
#include<stdio.h> #include<vector> using namespace std; struct E{ int next; int c; int cost; }; vector<E> edge[1001]; int dis[1001]; int cost[1001]; bool mark[1001]; int main(){ int n,m; int s,t; while(scanf("%d%d",&n,&m)!=EOF){ if(n==0 && m==0) break; for(int i=1;i<=n;i++){ edge[i].clear(); } while(m--){ int a,b,c,cost; scanf("%d%d%d%d",&a,&b,&c,&cost); E temp; temp.c=c; temp.cost=cost; temp.next=b; edge[a].push_back(temp); temp.next=a; edge[b].push_back(temp); } scanf("%d%d",&s,&t); for(int i=1;i<=n;i++){ dis[i]=-1; mark[i]=false; } dis[s]=0; mark[s]=true; int newp=s; for(int i=1;i<n;i++){ for(int j=0;j<edge[newp].size();j++){ int t=edge[newp][j].next; int c=edge[newp][j].c; int co=edge[newp][j].cost; if(mark[t]==true) continue; if(dis[t]==-1 || dis[t]>dis[newp]+c || dis[t]==dis[newp]+c && cost[t]>cost[newp]+co){ dis[t]=dis[newp]+c; cost[t]=cost[newp]+co; } } int min=999999999; for(int j=1;j<=n;j++){ if(mark[j]==true) continue; if(dis[j]==-1) continue; if(dis[j]<min){ min=dis[j]; newp=j; } } mark[newp]=true; } printf("%d %d\n",dis[t],cost[t]); } return 0; }
标签:back family next break 长度 using bsp class min
原文地址:https://www.cnblogs.com/bernieloveslife/p/9736501.html