博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Codeforces Round #261 (Div. 2) E]Pashmak and Graph(Dp)
阅读量:5943 次
发布时间:2019-06-19

本文共 1101 字,大约阅读时间需要 3 分钟。

Description

Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in solving the problem.

You are given a weighted directed graph with n vertices and m edges. You need to find a path (perhaps, non-simple) with maximum number of edges, such that the weights of the edges increase along the path. In other words, each edge of the path must have strictly greater weight than the previous edge in the path.

Help Pashmak, print the number of edges in the required path.

Solution

题意:给出一个无自环、重边的带权有向图,求边权严格递增的最长的路径(可以是非简单路径)

思路题QAQ

O(mlogm)以边权排序后再逐个处理,这样就保证了递增,然后可以O(m)求解,维护每个点作为结尾的最长的边权上升路径的长度

注意边权相等的情况要放在一起处理

#include
#include
#include
#include
#include
#define MAXN 300010using namespace std;int n,m,f[MAXN],g[MAXN];struct Node{ int u,v,w; bool operator < (const Node& x) const {
return w

 

转载于:https://www.cnblogs.com/Zars19/p/6917791.html

你可能感兴趣的文章
LBS突围:从微信到微博
查看>>
SFB 项目经验-40-Skype for Business-呼入正常-呼出不正常
查看>>
吴忌寒江卓尔批“闪电网络”背后,是链圈和矿圈的的利益之争
查看>>
python的cls,self,classmethod,staticmethod
查看>>
应用系统中常见报表类型解析
查看>>
[Silverlight入门系列]使用MVVM模式(9): 想在ViewModel中控制Storyboard动画?
查看>>
3 项目计划
查看>>
SQL Server 2008 下载地址(微软官方网站)
查看>>
如何对已经发布过的InfoPath模板进行修改
查看>>
推荐系统高峰论坛
查看>>
移动互联
查看>>
basic4android 开发教程翻译(三)IDE 小贴士
查看>>
看看async,await 是如何简化异步的调用WCF!
查看>>
obj-c 定义一个类
查看>>
电脑APK
查看>>
计数器的代码的原理分析
查看>>
HDU-4335 What is N? 欧拉函数,欧拉定理
查看>>
HDU 1044 Collect More Jewels(搜索,先bfs再dfs)
查看>>
使用RabbitMQ过程中遇到的一个问题(队列为空,但内存暴涨)以及与开发者的邮件沟通...
查看>>
C++/C学习笔记(九)
查看>>