求助!WA on #3 #9
  • 板块P1807 最长路
  • 楼主doooge
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/10/4 16:31
  • 上次更新2024/10/4 18:52:15
查看原帖
求助!WA on #3 #9
1286553
doooge楼主2024/10/4 16:31

代码:

#include <bits/stdc++.h>
using namespace std;
struct ll
{
	int x,w;
};
vector <ll> v[2010];
int dis[2010],n,m;
void spfa()
{
    memset(dis , -0x3f , sizeof(dis));
	queue <int> q;
	q.push(1);
	dis[1] = 0;
	while (!q.empty())
	{
		int tmp = q.front();
		q.pop();
		for (auto i : v[tmp])
		{
			if (dis[i.x] < dis[tmp] + i.w)
			{
				dis[i.x] = dis[tmp] + i.w;
				q.push(i.x);
			}
		}
	}
	if (dis[n] > 1e9) cout << "INF" << endl;
    else cout << dis[n] << endl;
	return;
}
int main()
{
	cin >> n >> m;
	for (int i = 1 ; i <= m ; i++)
	{
		int x,y,w;
		cin >> x >> y >> w;
		v[x].push_back({y , w});
	}
	spfa();
	return 0;
}

玄一关

2024/10/4 16:31
加载中...