# ICPC2017网络赛（乌鲁木齐）H: Skiing （SPFA最长路）

H: Skiing

time limit 1000ms memory limit 131072KB

i i
In this winter holiday, Bob has a plan for skiing at the mountain resort. This ski resort has M diﬀerent ski paths and N diﬀerent ﬂags situated at those turning points. The i-th path from the S -th ﬂag to the T -th ﬂag has length L . Each path must follow the principal of reduction of heights and the start point must be higher than the end point strictly. An available ski trail would start from a ﬂag, passing through several ﬂags along the paths, and end at another ﬂag. Now, you should help Bob ﬁnd the longest available ski trail in the ski resort. Input Format The ﬁrst line contains an integer T, indicating that there are T cases. In each test case, the ﬁrst line contains two integers N and M where 0 < N ≤ 10000 and 0 < M ≤ 100000 as described above. Each of the following M lines contains three integers S , T , and L  (0 < L < 1000) describing a path in the ski resort. Output Format For each test case, ouput one integer representing the length of the longest ski trail. Sample Input
1 5 4 1 3 3 2 3 4 3 4 1 3 5 2
Sample Output
6

【题意】：

【解析】：

【代码】：

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#define mset(a,i) memset(a,i,sizeof(a))
using namespace std;
typedef long long ll;
struct node{
int to,val,next;
}e[101010];
int n,m,x,y,val,cnt ;
ll dis[10101];
queue <int> Q ;
{
e[cnt] = (node){ y,v,head[x] } ;
}
void SPFA(int s)
{
int u,v;
while(!Q.empty())Q.pop();
Q.push(s);
while(!Q.empty())
{
u=Q.front() ;
Q.pop() ;
{
v=e[i].to;
if(dis[v]<dis[u]+e[i].val)
{
dis[v]=dis[u]+e[i].val;
Q.push(v);
}
}
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
mset(IN,0);
mset(dis,0);
cnt=0;
scanf("%d%d",&n,&m) ;
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&val);
IN[y]++;
}
if(n==1)
{
printf("0\n");
continue;
}
for(int i=1;i<=n;i++)
{
if(IN[i]==0)
SPFA(i);
}
ll ans=0;
for(int i=1;i<=n;i++)
{
ans=max(ans,dis[i]);
}
printf("%lld\n",ans);
}
return 0 ;
}

#### 2017 ACM/ICPC 新疆站总结

2017-12-04 22:58:57

#### spfa求最长路

2014-05-26 18:09:54

#### hdu3696(spfa求最长路)

2017-07-02 14:14:57

#### 图算法补充（SPFA，最长路径）

2015-07-29 19:53:06

#### 2017乌鲁木齐网络赛 skiing（spfa/bellman最长路模板题）

2017-09-12 21:28:03

#### 2017 ACM-ICPC 亚洲区（乌鲁木齐赛区）网络赛-A. Banana

2017-09-09 13:45:37

#### 2017 ACM-ICPC 亚洲区（乌鲁木齐赛区）网络赛

2017-09-09 12:17:26

#### 2017 ACM-ICPC 亚洲区（乌鲁木齐赛区）网络赛 题解

2017-09-11 01:02:57

#### 2017 ACM-ICPC 亚洲区（乌鲁木齐赛区）网络赛 - A C F H

2017-09-10 18:22:50