2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H. Skiing
2017-09-09 21:01
393 查看
In
this winter holiday, Bob has a plan for skiing at the mountain resort.
This ski resort has MM different
ski paths and NN different
flags situated at those turning points.
The ii-th
path from the S_iSi-th
flag to the T_iTi-th
flag has length L_iLi.
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 flag, passing through several flags along the paths, and end at another flag.
Now, you should help Bob find the longest available ski trail in the ski resort.
The first line contains an integer TT,
indicating that there are TT cases.
In each test case, the first line contains two integers NN and MM where 0
< N \leq 100000<N≤10000 and 0
< M \leq 1000000<M≤100000as
described above.
Each of the following MM lines
contains three integers S_iSi, T_iTi,
and L_i~(0
< L_i < 1000)Li (0<Li<1000) describing
a path in the ski resort.
For each test case, ouput one integer representing the length of the longest ski trail.
2017
ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
题意:有向图求最长路
解题思路:DP求最长路,用到了Floyd的思想,把每一点的最长路都求一遍,记录最大即可
this winter holiday, Bob has a plan for skiing at the mountain resort.
This ski resort has MM different
ski paths and NN different
flags situated at those turning points.
The ii-th
path from the S_iSi-th
flag to the T_iTi-th
flag has length L_iLi.
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 flag, passing through several flags along the paths, and end at another flag.
Now, you should help Bob find the longest available ski trail in the ski resort.
Input Format
The first line contains an integer TT,indicating that there are TT cases.
In each test case, the first line contains two integers NN and MM where 0
< N \leq 100000<N≤10000 and 0
< M \leq 1000000<M≤100000as
described above.
Each of the following MM lines
contains three integers S_iSi, T_iTi,
and L_i~(0
< L_i < 1000)Li (0<Li<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.样例输入
1 5 4 1 3 3 2 3 4 3 4 1 3 5 2
样例输出
6
题目来源
2017ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
题意:有向图求最长路
解题思路:DP求最长路,用到了Floyd的思想,把每一点的最长路都求一遍,记录最大即可
#include<iostream> #include<deque> #include<memory.h> #include<stdio.h> #include<map> #include<string> #include<algorithm> #include<vector> #include<math.h> #include<stack> #include<queue> #include<set> #define INF 1<<29 #define MAXN 100005 using namespace std; const int MAXV=100005; int max(int a,int b){ return a>b?a:b; } int dp[100005]; struct edge{ int v1,v2,w,next; }e[MAXV]; int edge_num; int head[MAXV]; void insert_edge(int v1,int v2,int w){ e[edge_num].v1=v1; e[edge_num].v2=v2; e[edge_num].w=w; e[edge_num].next=head[v1]; head[v1]=edge_num++; } int dr(int i) { if(dp[i]) return dp[i]; for(int j=head[i];j!=-1;j=e[j].next) dp[i]=max(dp[i],dr(e[j].v2)+e[j].w); return dp[i]; } int main() { int t; scanf("%d",&t); while(t--){ int a,m; memset(dp,0,sizeof(dp)); edge_num=0; memset(head,-1,sizeof(head)); scanf("%d%d",&a,&m); int t1,t2,t3; for(int i=0;i<m;i++){ scanf("%d%d%d",&t1,&t2,&t3); insert_edge(t1,t2,t3); } int ans=0; for(int i=1;i<=a;i++) ans=max(ans,dr(i)); printf("%d\n",ans); } return 0; }
相关文章推荐
- Skiing( 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 )
- 计蒜客 16957 Skiing(2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H)
- H. Skiing 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
- 计蒜客-2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛-H-Skiing
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 A. Banana(连通性水题)
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 Islands
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 E: Half-consecutive Numbers
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 C. Coconut(签到)
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 G
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 - J Our Journey of Dalian Ends(最小费用最大流)
- 计蒜客 16952 Coconut(2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 C)
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛---Half-consecutive Numbers
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 F. Islands(有向图加边变成一个强连通图)
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区) 网络赛 H.Skiing(求有向无环图的最长路)
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 F. Islands
- 计蒜客 16954 Half-consecutive Numbers(2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 E)
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛- A. Banana
- 计蒜客-2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题Skiing(拓扑序求DAG最长路)
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛(9.9)