大佬救命啊,67分这个坎过不去了
查看原帖
大佬救命啊,67分这个坎过不去了
425051
超级赛亚人楼主2021/8/15 14:20

大佬救命啊,67分这个坎过不去了

#include<bits/stdc++.h>
using namespace std;
struct edge{
	int to,w,next;
}e[50001];
int head[1501],cnt,f[1501],in[1501];
void add(int from,int to,int w)
{
	in[to]++;
	cnt++;
	e[cnt].to=to;
	e[cnt].w=w;
	e[cnt].next=head[from];
	head[from]=cnt;
}
queue <int> q;
int main()
{
	int n,m;
	cin>>n>>m;
	int a,b,c;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&a,&b,&c);
		add(a,b,c);
	}
	q.push(1);
	int x,to;
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		for(int i=head[x];i;i=e[i].next)
		{
			to=e[i].to;
			f[to]=max(f[x]+e[i].w,f[to]);
			in[to]--;
			if(in[to]==0)
			{
				q.push(to);
			}
		}
	}
	if(f[n])
	cout<<f[n];
	else
	cout<<-1;
}
2021/8/15 14:20
加载中...