CF459E Pashmak and Graph

Posted isaunoya

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF459E Pashmak and Graph相关的知识,希望对你有一定的参考价值。

dp,我们考虑到,这个其实你只需要按照边权排序,然后直接更新答案就完事了。
如果要求多维递增,那么就是个多维数点问题,查一下最值就可以了。

// by Isaunoya
#include<bits/stdc++.h>
using namespace std;
struct io {
	char buf[1 << 23 | 3], *s;
	int f;
	io() { f = 0, buf[fread(s = buf, 1, 1 << 23, stdin)] = ‘
‘; }
	io& operator >> (int&x) {
		for(x = f = 0; !isdigit(*s); ++s) f |= *s  == ‘-‘;
		while(isdigit(*s)) x = x * 10 + (*s++ ^ 48);
		return x = f ? -x : x, *this;
	}
};

const int maxn = 3e5 + 53;
vector <pair<int,int>> V[233333];
int dp[maxn], tmp[maxn];

signed main() {
#ifdef LOCAL
	freopen("testdata.in", "r", stdin);
#endif
	io in;
	int n, m;
	in >> n >> m;
	while(m --) {
		int u, v, w;
		in >> u >> v >> w;
		V[w].push_back({u, v});
	}
	for(int i = 1 ; i <= 1e5 ; i ++) {
		for(auto x : V[i]) { tmp[x.first] = dp[x.first]; }
		for(auto x : V[i]) {
			int u = x.first, v = x.second;
			dp[v] = max(dp[v], tmp[u] + 1);
		}
	}
	int ans = 1;
	for(int i = 1 ; i <= n ; i ++) ans = max(ans, dp[i]);
	cout << ans << ‘
‘;
	return 0;
}

以上是关于CF459E Pashmak and Graph的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces 459E Pashmak and Graph:dp + 贪心

[Codeforces Round #261 (Div. 2) E]Pashmak and Graph(Dp)

CF#459 A Pashmak and Garden (水题)

CF459C Pashmak and Buses 打印全排列

CF #261 div2 D. Pashmak and Parmida&#39;s problem (树状数组版)

CF459D Pashmak and Parmida's problem [树状数组]