zoukankan      html  css  js  c++  java
  • bzoj2763 最短路

    速度卡进第一页。。在我看来相当于拆点

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 #include<vector>
     7 #include<queue>
     8 #define rep(i,l,r) for(int i=l;i<r;i++)
     9 #define clr(a,x) memset(a,x,sizeof(a))
    10 using namespace std;
    11 int read()
    12 {
    13     char c;
    14     c=getchar();
    15     while(!isdigit(c)) c=getchar();
    16     int ans=0;
    17     while(isdigit(c)){
    18         ans=ans*10+c-'0';
    19         c=getchar();
    20     }
    21     return ans;
    22 }
    23 struct edge{
    24     int to,v;
    25 };
    26 struct node{
    27     int num,d,f;
    28     bool operator <(const node&q)const{
    29         return d>q.d;
    30     }
    31 };
    32 const int maxn=10005,maxm=50005,maxk=15;
    33 int n,m,k,s,t,d[maxn][maxk];
    34 bool p[maxn][maxk];
    35 priority_queue<node>q;
    36 vector<edge>e[maxn];
    37 int main()
    38 {   
    39     clr(p,0);
    40     node start;
    41     start.d=0;
    42     start.f=0;
    43     n=read();
    44     m=read();
    45     k=read();
    46     start.num=read();
    47     int end=read();
    48     rep(i,0,n)
    49         rep(j,0,k+1)
    50             d[i][j]=10000000;
    51     rep(i,0,k+1) d[start.num][i]=0;
    52     rep(i,0,m){
    53         edge ed;
    54         int from=read();
    55         ed.to=read();
    56         ed.v=read();
    57         e[from].push_back(ed);
    58         swap(from,ed.to);
    59         e[from].push_back(ed);
    60     }
    61     q.push(start);
    62     int cnt=0;
    63     while(!q.empty()){
    64         cnt++;
    65         node now=q.top(); 
    66         q.pop();
    67         if(p[now.num][now.f]) continue;
    68         p[now.num][now.f]=1;
    69         p[now.num][now.f]=1;
    70         rep(i,0,e[now.num].size()){
    71             if(now.d+e[now.num][i].v<d[e[now.num][i].to][now.f]){
    72                 d[e[now.num][i].to][now.f]=now.d+e[now.num][i].v;
    73                 node next;
    74                 next.f=now.f;
    75                 next.d=d[e[now.num][i].to][now.f];
    76                 next.num=e[now.num][i].to;
    77                 q.push(next);
    78             }
    79             if(now.d<d[e[now.num][i].to][now.f+1]){
    80                 d[e[now.num][i].to][now.f+1]=now.d;
    81                 node next;
    82                 next.f=now.f+1;
    83                 next.d=now.d;
    84                 next.num=e[now.num][i].to;
    85                 q.push(next);;
    86             }
    87         }
    88     }
    89     printf("%d",d[end][k]);
    90     return 0;
    91 }
    View Code

    2763: [JLOI2011]飞行路线

    Time Limit: 10 Sec  Memory Limit: 128 MB
    Submit: 1080  Solved: 431
    [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]
  • 相关阅读:
    利用事件委托实现用户控件中的行为触发所在页面的处理函数
    mootools系列:打造属于你自己的Popup(弹出框)——基本结构篇
    mootools系列:打造属于你自己的Popup(弹出框)——外观及应用篇
    所见即所得的Excel报表生成(二)——从Html table到Excel Cell
    Excel操作服务器端配置
    顺丰单号生成规则
    代理模式Proxy
    解释器模式Interpreter
    线性表
    总有一款合适的框架
  • 原文地址:https://www.cnblogs.com/chensiang/p/4623112.html
Copyright © 2011-2022 走看看