zoukankan      html  css  js  c++  java
  • Heavy Transportation POJ

    Heavy Transportation
    Time Limit: 3000MS   Memory Limit: 30000K
    Total Submissions: 65250   Accepted: 16053

    Description

    Background
    Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight.
    Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know.

    Problem
    You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing n (the customer's place). You may assume that there is at least one path. All streets can be travelled in both directions.

    Input

    The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one street between each pair of crossings.

    Output

    The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.

    Sample Input

    1
    3 3
    1 2 3
    1 3 4
    2 3 5
    

    Sample Output

    Scenario #1:
    4
    

    Source

    TUD Programming Contest 2004, Darmstadt, Germany

    [Submit]   [Go Back]   [Status]   [Discuss]

     

     

    题意

      在一张无向图找一条最长路,并记录这条路上的最小边权,不知道为什么前向星会TLE,是因为多组输入的memset?

    CODE

     

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <queue>
     6 #include <vector>
     7 
     8 using namespace std;
     9 typedef pair<int,int> P;
    10 typedef long long LL;
    11 const int inf = 0x3f3f3f3f;
    12 const int maxn = 1e3+7;
    13 const int kmaxn = 1e6 + 7;
    14 
    15 int dis[maxn];
    16 int cnt=0;
    17 int n,m;
    18 
    19 struct node
    20 {
    21     int to,w;
    22 };
    23 
    24 vector <node> g[maxn];
    25 /*inline void add(int u,int v,int w)
    26 {
    27     edge[cnt].to=v;
    28     edge[cnt].w=w;
    29     edge[cnt].nxt=head[u];
    30     head[u]=cnt++;
    31 }*/
    32 
    33 /*void add(int u,int v,int w) {
    34     edge[++cnt].to=v;
    35     edge[cnt].nxt=head[u];
    36     edge[cnt].w=w;
    37     head[u]=cnt;
    38 }*/
    39 
    40 void dijkstra() {
    41     //memset(vis,0,sizeof(vis));
    42     memset(dis,0,sizeof(dis));
    43     priority_queue<P,vector<P>,less<P> >q;
    44     dis[1]=inf;
    45     q.push(make_pair(inf,1));
    46     while(!q.empty()) {
    47         P p = q.top();
    48         int u=q.top().second;
    49         q.pop();
    50         if(p.first < dis[u])
    51             continue;
    52         int d = g[u].size();
    53         //printf("size:%d
    ",d);
    54         for(int i = 0; i < d; i++) {
    55             node e = g[u][i];
    56             int v=e.to,z=e.w;
    57             if(dis[u] > dis[v] && z > dis[v]) {
    58                 dis[v] = min(z,dis[u]);
    59                 q.push(P(dis[v],v));
    60             }
    61         }
    62     }
    63 }
    64 
    65 int main()
    66 {
    67     int T;
    68     scanf("%d",&T);
    69     int cnt = 0;
    70     while(T--) {
    71         scanf("%d %d",&n, &m);
    72         //memset(head, 0,sizeof(head));
    73         //memset(edge, 0,sizeof(edge));
    74         for(int i = 0; i <= n; i++) {
    75             g[i].clear();
    76         }
    77         int u,v,cost;
    78         for(int i=1;i<=m;i++) {
    79             scanf("%d %d %d",&u, &v, &cost);
    80             g[u].push_back({v,cost});
    81             g[v].push_back({u,cost});
    82         }
    83         dijkstra();
    84         printf("Scenario #%d:
    %d
    
    ",++cnt,dis[n]);
    85     }
    86     return 0;
    87 }
    View Code

     

     

  • 相关阅读:
    .net对象生命周期 一) 转载
    HTTP的版本 转载
    sql server sql语句判断是否有表备注并进行新增或修改
    sql server update触发器
    vs文件属性复制到输出目录 转载
    c#使用log4net记录日志 转载
    windows服务定时器 转载
    vs创建项目以后修改https为http
    消息队列 转载
    nmp 设置淘宝镜像
  • 原文地址:https://www.cnblogs.com/orangeko/p/12289220.html
Copyright © 2011-2022 走看看