Codeforces Round #261 (Div. 2) E (DP)

E. Pashmak and Graph

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.

Input

The first line contains two integers nm (2 ≤ n ≤ 3·105; 1 ≤ m ≤ min(n·(n - 1), 3·105)). Then, m lines follows. The i-th line contains three space separated integers: uiviwi (1 ≤ ui, vi ≤ n; 1 ≤ wi ≤ 105) which indicates that there‘s a directed edge with weight wi from vertex ui to vertex vi.

It‘s guaranteed that the graph doesn‘t contain self-loops and multiple edges.

Output

Print a single integer — the answer to the problem.

题意:求出给定图的单调不下降路径权值的最长路。

sl :直接排个序,然后dp搞一下,每条边相当于一个限制条件。但是注意的是,相同长度的不会被其更新,因此多开一数组记录就好了

Codeforces Round #261 (Div. 2) E (DP)

时间: 2024-10-07 05:59:54

Codeforces Round #261 (Div. 2) E (DP)的相关文章

Codeforces Round 261 Div.2 E Pashmak and Graph --DAG上的DP

题意:n个点,m条边,每条边有一个权值,找一条边数最多的边权严格递增的路径,输出路径长度. 解法:先将边权从小到大排序,然后从大到小遍历,dp[u]表示从u出发能够构成的严格递增路径的最大长度. dp[u] = max(dp[u],dp[v]+1),因为有重复的边权值,所以用dis数组先记录,到不重复时一起更新重复的那些边权. 代码: (非原创) #include <iostream> #include <cstdio> #include <cstring> #incl

Codeforces Round #261 (Div. 2)[ABCDE]

Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden 题意: 一个正方形,它的边平行于坐标轴,给出这个正方形的两个点,求出另外两个点. 分析: 推断下是否平行X轴或平行Y轴,各种if. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: A.cpp * Create Date: 2014-0

Codeforces Round #261 (Div. 2)

A. Pashmak and Garden 题意:已知两个顶点的坐标,如果能推断出另外两个顶点则输出(special judge).如果这两个顶点不是构成正方形的两个顶点, 则输出-1. 水题,1A,不多说. #include<cstdio> #include<iostream> #include<cstring> #include<cmath> using namespace std; int main() { int x1,x2,y1,y2,flag,x

Codeforces Round #261 (Div. 2)——Pashmak and Graph

题目链接 题意: n个点,m个边的有向图,每条边有一个权值,求一条最长的路径,使得路径上边值严格递增.输出路径长度 (2?≤?n?≤?3·105; 1?≤?m?≤?min(n·(n?-?1),?3·105)) 分析: 因为路径上会有重复点,而边不会重复,所以最开始想的是以边为状态进行DP,get TLE--后来想想,在以边为点的新图中,边的个数可能会很多,所以不行. 考虑一下裸的DP如何做:路径上有重复点,可以将状态详细化,dp[i][j]表示i点以j为结束边值的最长路,但是数据不允许这样.想想

Codeforces Round #261 (Div. 2) 459B. Pashmak and Flowers(数学题,组合)

题目链接:http://codeforces.com/problemset/problem/459/B B. Pashmak and Flowers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pashmak decided to give Parmida a pair of flowers from the garden.

Codeforces Round #261 (Div. 2)459A. Pashmak and Garden(数学题)

题目链接:http://codeforces.com/problemset/problem/459/A A. Pashmak and Garden time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pashmak has fallen in love with an attractive girl called Parmida s

Codeforces Round #261 (Div. 2) D 树状数组应用

看着题意:[1,i]中等于a[i]的个数要大于[,jn]中等于a[j]的个数 且i<j,求有多少对这样的(i,j)  ,i<j但是 i前面的合法个数 要大于j后面的 看起来很像逆序数的样子,所以很容易往树状数组想去,但是处理就看个人了,像我比赛的时候就处理得非常的麻烦,虽做出了但是花时间也多,经过杰哥的教育,其实正着塞进树状数组 反着来找就可以了,灰常的简单清晰明了,贴一发纪念我的搓比 int n; int aa[1000000 + 55]; int bb[1000000 + 55]; int

Codeforces Round #261 (Div. 2) D. Pashmak and Parmida&#39;s problem (树状数组求逆序数 变形)

题目链接 题意: 给出一些数a[n],求(i, j), i<j 的数量,使得:f(1, i, a[i]) > f(j, n, a[j]) . f(lhs, rhs, x) 指在 { [lhs, rhs]范围中,a[k]的值=x } 的数量. 1.  f(1, i, a[i]) 就是指a[i]前面包括a[i]的数中,有几个值=a[i]. 2.  f(j, n, a[j]) 就是指a[j]后面包括a[j]的数中有几个值=a[j]. 虽然a[x]范围不小,但是n的范围是1000,不是很大,所以我们可

Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida&#39;s problem(求逆序数对)

题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Parmida is a clever girl and she wants to participate in O