zoukankan      html  css  js  c++  java
  • 3408: [Usaco2009 Oct]Heat Wave 热浪

    3408: [Usaco2009 Oct]Heat Wave 热浪

    Time Limit: 3 Sec  Memory Limit: 128 MB
    Submit: 67  Solved: 55
    [Submit][Status][Discuss]

    Description

    Input

     第1行:4个由空格隔开的整数T,C,Ts,Te.
     第2到第C+1行:第i+l行描述第i条道路.有3个由空格隔开的整数Rs,Re,Ci.

    Output

        一个单独的整数表示Ts到Te的最小费用.数据保证至少存在一条道路.

    Sample Input

    7 11 5 4
    2 4 2
    1 4 3
    7 2 2
    3 4 3
    5 7 5
    7 3 3
    6 1 1
    6 3 4
    2 4 3
    5 6 3
    7 2 1

    Sample Output

    7

    HINT

     

    Source

    Gold

    题解:话说USACO金组为啥时候冒出来这么多普及组题= =

    最短路模板题不解释

     1 /**************************************************************
     2     Problem: 3408
     3     User: HansBug
     4     Language: Pascal
     5     Result: Accepted
     6     Time:48 ms
     7     Memory:5496 kb
     8 ****************************************************************/
     9  
    10 type
    11     point=^node;
    12     node=record
    13                g,w:longint;
    14                next:point;
    15     end;
    16 var
    17    i,j,k,l,m,n,s,t,f,r:longint;
    18    a:array[0..100000] of point;
    19    c,g:array[0..100000] of longint;
    20    d:array[0..1000000] of longint;
    21    p:point;
    22 procedure add(x,y,z:longint);
    23           var p:point;
    24           begin
    25                new(p);p^.g:=y;p^.w:=z;
    26                p^.next:=a[x];a[x]:=p;
    27           end;
    28 begin
    29      readln(n,m,s,t);
    30      for i:=1 to n do a[i]:=nil;
    31      for i:=1 to m do
    32          begin
    33               readln(j,k,l);
    34               add(j,k,l);add(k,j,l);
    35          end;
    36      fillchar(g,sizeof(g),0);
    37      fillchar(c,sizeof(c),0);
    38      f:=1;r:=2;d[1]:=s;c[s]:=1;g[s]:=1;
    39      while f<r do
    40            begin
    41                 p:=a[d[f]];
    42                 while p<>nil do
    43                       begin
    44                            if (c[p^.g]=0) or ((c[p^.g]>0) and (c[p^.g]>(c[d[f]]+p^.w))) then
    45                               begin
    46                                    c[p^.g]:=c[d[f]]+p^.w;
    47                                    if g[p^.g]=0 then
    48                                       begin
    49                                            g[p^.g]:=1;
    50                                            d[r]:=p^.g;
    51                                            inc(r);
    52                                       end;
    53                               end;
    54                            p:=p^.next;
    55                       end;
    56                 g[d[f]]:=0;
    57                 inc(f);
    58            end;
    59      for i:=1 to n do dec(c[i]);
    60      writeln(c[t]);
    61      readln;
    62 end.   
  • 相关阅读:
    Error: That port is already in use.
    笔记:django is not a registered namespace错误
    笔记:常用SQL语句
    django迁移数据库错误
    OperationalError: (1044, "Access denied for user ''@'localhost' to database 'mydb'")
    笔记:LNMP架构Web的高并发处理
    Debian ZSH解决每次ssh都需要source .bashrc问题
    Django第四天:博客项目实战
    js模板引擎之 Handlebars 基本用法
    创建发布自己的npm包
  • 原文地址:https://www.cnblogs.com/HansBug/p/4418567.html
Copyright © 2011-2022 走看看