51nod最长递增路径:(还不错的图)
Input第1行:2个数N, M,N为节点的数量,M为边的数量(1 <= N <= 50000, 0 <= M <= 50000)。节点编号为0 至 N - 1。
第2 - M + 1行:每行3个数S, E, W,表示从顶点S到顶点E,有一条权值为W的边(0 <= S, E <= N - 1, 0 <= W <= 10^9)。Output输出最长路径的长度。Sample Input
6 8
0 1 4
1 2 3
1 3 2
2 3 5
3 4 6
4 5 6
5 0 8
3 2 7
Sample Output
4
题意:在图中找最长路径,边权递增。
思路:不能直接以点为状态,因为不知道最后一次的长度。所以以边为最后状态,但是为了表面方向,就把每条边拆成两条。所以我直接用存边的信息来表示表示状态。
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
const int maxn=;
int Laxt[maxn],Next[maxn],To[maxn],cost[maxn],cnt;
P lin[maxn]; int l[maxn],r[maxn],dis[maxn],ans;
void add(int u,int v,int c)
{
Next[++cnt]=Laxt[u];
Laxt[u]=cnt; To[cnt]=v;
cost[cnt]=c;
}
int main()
{
int N,M,u,v,c,i,j;
scanf("%d%d",&N,&M);
for(i=;i<=M;i++){
scanf("%d%d%d",&l[i],&r[i],&c);
add(l[i],r[i],c); add(r[i],l[i],c);
lin[i]=P(c,i);
}
sort(lin+,lin+M+);
for(i=;i<=cnt;i++) dis[i]=;
for(i=;i<=M;i++){
int Ln=lin[i].second,Ct=lin[i].first;
for(j=Laxt[l[Ln]];j;j=Next[j]){
if(cost[j]>Ct) {
dis[j]=max(dis[j],dis[*Ln]+);
ans=max(ans,dis[j]);
}
}
for(j=Laxt[r[Ln]];j;j=Next[j]){
if(cost[j]>Ct) {
dis[j]=max(dis[j],dis[*Ln-]+);
ans=max(ans,dis[j]);
}
} }
printf("%d\n",ans);
return ;
}
/*
2 4
0 1 1
1 0 2
0 1 3
1 0 4
*/
51nod最长递增路径:(还不错的图)的更多相关文章
- [LeetCode] Longest Increasing Path in a Matrix 矩阵中的最长递增路径
Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...
- 51nod1274 最长递增路径
将边排序后dp一下就可以了. #include<cstdio> #include<cstring> #include<cctype> #include<alg ...
- [Swift]LeetCode329. 矩阵中的最长递增路径 | Longest Increasing Path in a Matrix
Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...
- Leetcode 329.矩阵中的最长递增路径
矩阵中的最长递增路径 给定一个整数矩阵,找出最长递增路径的长度. 对于每个单元格,你可以往上,下,左,右四个方向移动. 你不能在对角线方向上移动或移动到边界外(即不允许环绕). 示例 1: 输入: n ...
- Leetcode之深度优先搜索(DFS)专题-329. 矩阵中的最长递增路径(Longest Increasing Path in a Matrix)
Leetcode之深度优先搜索(DFS)专题-329. 矩阵中的最长递增路径(Longest Increasing Path in a Matrix) 深度优先搜索的解题详细介绍,点击 给定一个整数矩 ...
- 【题解】最长递增路径 [51nod1274]
[题解]最长递增路径 [51nod1274] 传送门:最长递增路径 \([51nod1274]\) [题目描述] 一个可能有自环有重边的无向图,每条边都有边权.输入两个整数 \(n,m\) 表示一共 ...
- LeetCode. 矩阵中的最长递增路径
题目要求: 给定一个整数矩阵,找出最长递增路径的长度. 对于每个单元格,你可以往上,下,左,右四个方向移动. 你不能在对角线方向上移动或移动到边界外(即不允许环绕). 示例: 输入: nums = [ ...
- Java实现 LeetCode 329 矩阵中的最长递增路径
329. 矩阵中的最长递增路径 给定一个整数矩阵,找出最长递增路径的长度. 对于每个单元格,你可以往上,下,左,右四个方向移动. 你不能在对角线方向上移动或移动到边界外(即不允许环绕). 示例 1: ...
- 【原创】PicUploader: 一个还不错的图床工具
PicUploader PicUploader 是一个用php编写的图床工具,它能帮助你快速上传你的图片到云图床,并自动返回Markdown格式链接到剪贴板.配置完成后,要获取一个可用于markdow ...
随机推荐
- [Javascript] Await a JavaScript Promise in an async Function with the await Operator
The await operator is used to wait for a promise to settle. It pauses the execution of an async func ...
- css3 - 动态伪类
动态伪类分为以下几种: 1. hover(经过) 2. active(点击后) 3. focus(聚焦) - input专用 4. visited(访问后) 使用:
- C 标准库 - <signal.h>
C 标准库 - <signal.h> 简介 signal.h 头文件定义了一个变量类型 sig_atomic_t.两个函数调用和一些宏来处理程序执行期间报告的不同信号. 库变量 下面是头文 ...
- hdu5373
题先附上:水题,可是思路不正确,特easy超时(TLE) The shortest problem Time Limit: 3000/1500 MS (Java/Others) Memory L ...
- weblogic中部署项目报错org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken .
原因: 原因是weblogic要查找自己的antlr,和lib下面的antlr包冲突.... 解决方法: 在weblogic.xml添加 <container-descriptor> ...
- jquery+css实现网页颜色主题变换(只改变已设置好的几种颜色主题)
又遇到颜色主题变化,这次使用了jquery+css,使用了函数传值,而不是之前网站换肤改变link的方法. 首先是设置好颜色主题后,点击改变页面颜色主题.(需要自行导入jquery.js后查看效果) ...
- Qt5的插件机制(6)--开发Qt插件时几个重要的宏
怎样开发Qt插件,能够在Qt Assistant 中搜索"Qt Plugins"或"How to Create Qt Plugins",看看那篇manual中的 ...
- ok6410[002] ubuntu1604系统下搭配ckermit和dnw基于RAM的裸机程序调试环境
ubuntu1604系统下搭配ckermit和dnw基于RAM的裸机程序调试环境 系统: ubuntu16.04 裸板: 飞凌公司OK6410开发板 目标:搭建基于ubuntu1604系统和基于RA ...
- Effective Java - [2. 创建与销毁对象]
让对象的创建与销毁在掌控中. Item 1: 使用静态工厂方法而非使用构造函数 public static Boolean valueOf(boolean b) { return b ? Boolea ...
- C语言预处理条件语句的 与或运算
1.#ifdef 与或运算 #ifdef (MIN) && (MAX) ----------------------------错误使用 #if defined(MIN) & ...