zoukankan      html  css  js  c++  java
  • POJ 1062 昂贵的聘礼 最短路 难度:0

    http://poj.org/problem?id=1062

    #include <iostream>
    #include <cstring>
    #include <queue>
    using namespace std;
    int m,n;
    struct adjlist{
        int c[101],t[101];
    }a[101];
    int d[101],tm[101],l[101],r[101];
    queue<int >que;
    int abs(int x){
        return x>0?x:-x;
    }
    int spfa(int ls,int ll){
        que.push(1);
        int f,t;
        r[1]=0;
        while(!que.empty()){
            f=que.front();
            que.pop();
            for(int i=0;i<tm[f];i++){
                t=a[f].t[i];
                if(l[t]<=ll&&l[t]>=ls&&r[t]>r[f]+a[f].c[i]){
                    r[t]=r[f]+a[f].c[i];
                    que.push(t);
                }
            }
        }
        int minn=1000000;
        for(int i=1;i<=n;i++){
            minn=min(minn,r[i]+d[i]);
        }
        return minn;
    }
    int main(){
        ios::sync_with_stdio(false);
        int temp;
        cin>>m>>n;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>l[i]>>tm[i];
            temp=tm[i];
            for(int j=0;j<temp;j++){
                cin>>a[i].t[j]>>a[i].c[j];
            }
        }
        int ans=10000;
        for(int i=l[1]-m;i<=l[1];i++){
            for(int j=1;j<=n;j++)r[j]=100000;
            ans=min(ans,spfa(i,i+m));
        }
        cout<<ans<<endl;
        return 0;
    }
    

      

  • 相关阅读:
    51nod——T1267 4个数和为0
    cf220B莫队
    cf220b
    poj1436水平可见线
    poj2528贴海报,,
    poj3468
    hdu1698
    ural1989 单点更新+字符串hash
    cf Queries on a String
    hdu4605
  • 原文地址:https://www.cnblogs.com/xuesu/p/4754387.html
Copyright © 2011-2022 走看看