zoukankan      html  css  js  c++  java
  • bzoj2763: [JLOI2011]飞行路线

    多加一维进去dijkstra就可以了。。好像usaco有过。。

    #include<cstdio>
    #include<cstring>
    #include<cctype>
    #include<algorithm>
    #include<queue>
    using namespace std;
    #define rep(i,s,t) for(int i=s;i<=t;i++)
    #define dwn(i,s,t) for(int i=s;i>=t;i--)
    #define clr(x,c) memset(x,c,sizeof(x))
    #define qwq(x) for(edge *o=head[x];o;o=o->next)
    int read(){
        int x=0;char c=getchar();
        while(!isdigit(c)) c=getchar();
        while(isdigit(c)) x=x*10+c-'0',c=getchar();
        return x;
    }
    const int nmax=1e4+5;
    const int maxn=1e5+5;
    const int inf=0x7f7f7f7f;
    struct edge{
        int to,dist;edge *next;
    };
    edge es[maxn],*pt=es,*head[nmax];
    void add(int u,int v,int d){
        pt->to=v;pt->dist=d;pt->next=head[u];head[u]=pt++;
        pt->to=u;pt->dist=d;pt->next=head[v];head[v]=pt++;
    }
    int dist[nmax][11];
    struct node{
        int x,k,dist;
        node(int x,int k,int dist):x(x),k(k),dist(dist){};
        node(){};
        bool operator<(const node&rhs)const{
          return dist>rhs.dist;}
    };
    priority_queue<node>q;
    void dijkstra(int s,int t,int k){
        clr(dist,0x7f);dist[s][0]=0;q.push(node(s,0,0));
        node o;int ta,td,tk,to;
        while(!q.empty()){
            o=q.top();q.pop();ta=o.x,td=o.dist,tk=o.k;
            if(dist[ta][tk]!=td) continue;
            qwq(ta){
                to=o->to;
                if(dist[o->to][tk]>td+o->dist){
                    dist[o->to][tk]=td+o->dist;q.push(node(o->to,tk,td+o->dist));
                }
                if(tk<k&&dist[o->to][tk+1]>td){
                    dist[o->to][tk+1]=td;q.push(node(o->to,tk+1,td));
                }
            }
        }
        int ans=inf;
        rep(i,0,k) ans=min(ans,dist[t][i]);
        printf("%d
    ",ans);
        return ;
    }
    int main(){
        int n=read(),m=read(),k=read(),u,v,d,s=read(),t=read();
        rep(i,1,m) u=read(),v=read(),d=read(),add(u,v,d);
        dijkstra(s,t,k);
        return 0;
    }
    

      

    2763: [JLOI2011]飞行路线

    Time Limit: 10 Sec  Memory Limit: 128 MB
    Submit: 2484  Solved: 924
    [Submit][Status][Discuss]

    Description

    Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司。该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的价格。Alice和Bob现在要从一个城市沿着航线到达另一个城市,途中可以进行转机。航空公司对他们这次旅行也推出优惠,他们可以免费在最多k种航线上搭乘飞机。那么Alice和Bob这次出行最少花费多少?

    Input

    数据的第一行有三个整数,n,m,k,分别表示城市数,航线数和免费乘坐次数。
    第二行有两个整数,s,t,分别表示他们出行的起点城市编号和终点城市编号。(0<=s,t<n)
    接下来有m行,每行三个整数,a,b,c,表示存在一种航线,能从城市a到达城市b,或从城市b到达城市a,价格为c。(0<=a,b<n,a与b不相等,0<=c<=1000)
     

    Output

     
    只有一行,包含一个整数,为最少花费。

    Sample Input

    5 6 1
    0 4
    0 1 5
    1 2 5
    2 3 5
    3 4 5
    2 3 3
    0 2 100

    Sample Output

    8

    HINT

    对于30%的数据,2<=n<=50,1<=m<=300,k=0;


    对于50%的数据,2<=n<=600,1<=m<=6000,0<=k<=1;


    对于100%的数据,2<=n<=10000,1<=m<=50000,0<=k<=10.


    Source

     
    [Submit][Status][Discuss]
  • 相关阅读:
    配置对即时负载的优化
    通过重组索引提高性能
    使用索引视图提高性能
    sqlcmd
    (转)使用SQLCMD在SQLServer执行多个脚本
    在SQLServer处理中的一些问题及解决方法 NEWSEQUENTIALID()
    java反射机制与动态代理
    天天用的开发环境,你真的了解吗?
    通过IP获取对应所在地的地址
    unity3d KeyCode各键值说明
  • 原文地址:https://www.cnblogs.com/fighting-to-the-end/p/5885032.html
Copyright © 2011-2022 走看看