Coolest Ski Route

                                                         Coolest Ski Route

                                                                         时间限制: 1 Sec  内存限制: 128 MB
                                                                                   提交: 152  解决: 39
                                                                     提交] [状态] [讨论版] [命题人:admin]

题目描述

John loves winter. Every skiing season he goes heli-skiing with his friends. To do so, they rent a helicopter that flies them directly to any mountain in the Alps. From there they follow the picturesque slopes through the untouched snow.
Of course they want to ski on only the best snow, in the best weather they can get. For this they use a combined condition measure and for any given day, they rate all the available slopes.
Can you help them find the most awesome route?

 

输入

The input consists of:
•one line with two integers n (2 ≤ n ≤ 1000) and m (1 ≤ m ≤ 5000), where n is the number of (1-indexed) connecting points between slopes and m is the number of slopes.
•m lines, each with three integers s, t, c (1 ≤ s, t ≤ n, 1 ≤ c ≤ 100) representing a slope from point s to point t with condition measure c.
Points without incoming slopes are mountain tops with beautiful scenery, points without outgoing slopes are valleys. The helicopter can land on every connecting point, so the friends can start and end their tour at any point they want. All slopes go downhill, so regardless of where they start, they cannot reach the same point again after taking any of the slopes.

 

输出

Output a single number n that is the maximum sum of condition measures along a path that the friends could take.

 

样例输入

5 5
1 2 15
2 3 12
1 4 17
4 2 11
5 4 9

 

样例输出

40

 

提示

 

来源/分类

GCPC2018 

题意:

看起来很复杂,其实就是在有向图中找一条最长的路

刚开始用最短路的各种方法,各种WA,TLE,这么简单的一道题居然做成这个样子,好伤心

最后自己写了个dfs又超时了一发,简直了,马上又剪枝了一下,终于过啦~~~~~~

菜~~~

代码:

#include<bits/stdc++.h>
#define MAX 1005
using namespace std;
struct node
{
    int v,c;
    node () {}
    node(int x,int y)
    {
        v=x;
        c=y;
    }
};
int maxx;
vector<node>g[MAX];
int dis[1003];
int n,m;
int maxxx;
void  Dijkstra(int i)
{
    for(int j=0; j<g[i].size(); j++)
    {
        node u=g[i][j];
        if( dis[u.v]<dis[i]+u.c)
            dis[u.v]=dis[i]+u.c,maxxx=max(maxxx,dis[u.v]);
        else continue;//这句不加超时,在该点时之前已经计算过到该点更长的距离了,所以在以在此轮与该点相连的其他点不用再计算;
        Dijkstra(u.v);
    }
    return ;
}

int main()
{
    int x,y,z,i;
    while(~scanf("%d%d",&n,&m))
    {
        for (i=1; i<=m; i++)
        {
            scanf("%d%d%d",&x,&y,&z);
            g[x].push_back(node(y,z));
        }
        for(int j=1; j<=n; j++)  dis[j]=0;
        maxx=-1;
        for(int i=1; i<=n; i++)
        {
            maxxx=-1;
            Dijkstra(i);
            if(maxxx>maxx)maxx=maxxx;
        }
        printf("%d\n",maxx);
    }

    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值