WA on #35 求调
查看原帖
WA on #35 求调
964091
_6_awa楼主2025/1/19 08:37
#include <iostream>
#include <algorithm> 
using namespace std;
int n,m,ans[300005],d[300005],an;
struct node
{
	int u,v,w;
}a[300005];
bool cmp(node e,node f)
{
	return e.w < f.w;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
	cin >> n >> m;
	for(int i = 1;i <= m;i ++)cin >> a[i].u >> a[i].v >> a[i].w;
	sort(a + 1,a + m + 1,cmp);
	for(int i = 1;i <= m;i ++)
		if(a[i].w > d[a[i].u])
			if(ans[a[i].v] < ans[a[i].u] + 1)
			{
				ans[a[i].v] = ans[a[i].u] + 1;
				d[a[i].v] = a[i].w;
			}
	for(int i = 1;i <= n;i ++)an = max(an,ans[i]);
	cout << an;
}
2025/1/19 08:37
加载中...