1379. Cups Transportation

2067 단어 port
http://acm.timus.ru/problem.aspx?space=1&num=1379
이분 최 단 로
코드:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<string>

#include<map>

#include<vector>

#include<stack>

#include<set>

#include<map>

#include<queue>

#include<algorithm>

#include<cmath>

#define LL long long

#define sint short int

//#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const int N=505;

const int T=1440;

const int INF=1000000000;

int head[N],I;

bool had[N];

int dist[N];

int cost[N][N];

int limi[N][N];

int dijkstra(int x1,int x2,int n,int limit)

{

    for(int i=1;i<=n;++i)

    dist[i]=INF;

    memset(had,false,sizeof(had));

    dist[x1]=0;

    for(int w=1;w<=n;++w)

    {

        int k=-1;

        for(int i=1;i<=n;++i)

        if(!had[i]&&(k==-1||dist[i]<dist[k]))

        k=i;

        if(k==x2||dist[k]==INF)

        break;

        had[k]=true;

        for(int i=1;i<=n;++i)

        if(!had[i]&&limi[k][i]>=limit&&dist[k]+cost[k][i]<dist[i])

        dist[i]=dist[k]+cost[k][i];

    }

    return dist[x2];

}

int main()

{

    //freopen("data.in","r",stdin);

    int n,m;

    cin>>n>>m;

    for(int i=1;i<=n;++i)

    for(int j=1;j<=n;++j)

    {limi[i][j]=0;cost[i][j]=INF;}

    int l=1,r=0;

    while(m--)

    {

        int i,j,t,g;

        cin>>i>>j>>t>>g;

        g=max((g-3000000)/100,0);

        cost[i][j]=cost[j][i]=t;

        limi[i][j]=limi[j][i]=g;

        r=max(r,g);

    }

    if(n==1)

    {cout<<"10000000"<<endl;return 0;}

    while(l<=r)

    {

        int mid=(l+r)/2;

        if(dijkstra(1,n,n,mid)<=T)

        l=mid+1;

        else

        r=mid-1;

    }

    cout<<r<<endl;

    return 0;

}


좋은 웹페이지 즐겨찾기