2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H. Skiing
来源:互联网 发布:数据站点应当互不相同 编辑:程序博客网 时间:2024/05/05 10:16
In this winter holiday, Bob has a plan for skiing at the mountain resort.
This ski resort has M different ski paths and N different flags situated at those turning points.
The i-th path from the Si-th flag to the Ti-th flag has length Li.
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 T, indicating that there are T cases.
In each test case, the first line contains two integers N and M where 0<N≤10000 and 0<M≤100000as described above.
Each of the following M lines contains three integers Si, Ti, and 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.
样例输入
15 41 3 32 3 43 4 13 5 2
样例输出
6
题目来源
2017 ACM-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 100005using 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;}
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H. Skiing(记忆化dfs)
- H. Skiing 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H. Skiing
- 计蒜客-2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛-H-Skiing
- 计蒜客 16957 Skiing(2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H)
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛-H Skiing
- 【2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 】H Skiing 【求DAG图的最长路】
- Skiing( 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 )
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区) 网络赛 H.Skiing(求有向无环图的最长路)
- 计蒜客-2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题Skiing(拓扑序求DAG最长路)
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
- javascript的原型与原型链
- HAProxy+Varnish动静分离部署WordPress
- SSM框架搭建思路及流程
- 网络配置工具
- js对象
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H. Skiing
- 使用wait和notify来实现生产者和消费者
- Java的隐秘之JavaCC
- 使用Lock和Condition实现生产者和消费者
- HTTP请求错误400、401、402、403、404、405、406、407、412、414、500、501、502解析
- SpringMVC文件上传
- 随笔之框架原理
- Linux前台、后台、挂起、退出、查看命令汇总
- CSS知识点整理