• 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

     

     

  • 相关阅读:
    【BZOJ4903】
    nuxt中引入svg
    vue-spa微信分享,在ios端,分享不成功的原因及解决办法
    安装包
    nuxt中刷新页面后防止store值丢失
    nuxt项目如何设置代理接口
    nuxt引入jquery和bootstrap
    如何在nuxt中引入scss
    创建nuxt项目
    微信分享
  • 原文地址:https://www.cnblogs.com/orangeko/p/12289220.html
Copyright © 2020-2023  润新知