码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1839 未ac

时间:2015-06-11 14:35:06      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)  
#define maxn 500001
#define mod 10007
#define eps 1e-9
int Num;
char CH[20];
const int inf=0x7fffffff;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();}
    while(ch>=0&&ch<=9){x=x*10+ch-0;ch=getchar();}
    return x*f;
}
inline void P(int x)
{
    Num=0;if(!x){putchar(0);puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}
//**************************************************************************************

int n,m,t;
struct node
{
    int x;
    ll y;
    int z;
};
vector<node> e[maxn];
ll c[maxn];
int inq[maxn];
int d[maxn];
int solve(int v,int x)
{
    for(int i=1;i<=n;i++)
        d[i]=inf,inq[i]=0;
    d[v]=0;
    queue<int> q;
    q.push(v);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        inq[u]=0;
        for(int i=0;i<e[u].size();i++)
        {
            if(e[u][i].y>=x)
            if(d[e[u][i].x]>d[u]+e[u][i].z)
            {
                d[e[u][i].x]=d[u]+e[u][i].z;
                if(!inq[e[u][i].x])
                {
                    inq[e[u][i].x]=1;
                    q.push(e[u][i].x);
                }
            }
        }
    }
    return d[n];
}
int main()
{
    //test;
    int T=read();
    
    while(T--)
    {
        int n=read(),m=read(),t=read();
        for(int i=0;i<=n;i++)
            e[i].clear();
        memset(c,0,sizeof(c));
        for(int i=0;i<m;i++)
        {
            int a=read(),b=read();
            c[i]=read();
            int d=read();
            e[a].push_back((node){b,c[i],d});
            e[b].push_back((node){a,c[i],d});
        }
        sort(c,c+m);
        int l=0,r=m-1,mid;
        while(l<r)
        {
            mid=(l+r)>>1;
            int tmp=c[mid];
            if(solve(1,tmp)>t)
                l=mid+1;
            else
                r=mid;
        }
        cout<<c[l]<<endl;
    }
}

 

hdu 1839 未ac

标签:

原文地址:http://www.cnblogs.com/qscqesze/p/4568939.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!