求助大佬,为什么第四个点RE了
查看原帖
求助大佬,为什么第四个点RE了
261335
_Daota_楼主2020/5/6 00:45
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 105, M = 30000;
#define il inline
struct edge{
	int to, next, dis;
}e[M];
struct node
{
	int dis, pos;
	node(int d, int p):dis(d), pos(p) {}
	bool operator < (const node& x) const
	{
		return x.dis < dis;
	}
};
int n, head[N], cnt, dis[N];
bool vis[N];
priority_queue <node> q;

il void add_edge(int u, int v, int w);
il void dijkstra();

int main()
{
	scanf("%d", &n);
	memset(dis, 0x3f, sizeof(dis));
	memset(vis, 0, sizeof(vis));
	for (int i=1;i<=n-1;i++)
		for (int j=i+1;j<=n;j++)
		{
			int w;
			scanf("%d", &w);
			add_edge(i, j, w);
		}
	dijkstra();
	printf("%d\n", dis[n]);
	// printf("*************************************");
	return 0;
}

il void add_edge(int u, int v, int w)
{
	cnt++;
	e[cnt].to = v;
	e[cnt].dis = w;
	e[cnt].next = head[u];
	head[u] = cnt;
}
il void dijkstra()
{
	dis[1] = 0;
	q.push(node(0, 1));
	while (!q.empty())
	{
		node temp = q.top();
		q.pop();
		int u = temp.pos;
		if (vis[u])
			continue;
		vis[u] = true;
		for (int i=head[u];i;i=e[i].next)
		{
			int v = e[i].to;
			dis[v] = min(dis[v], dis[u]+e[i].dis);
			if (!vis[v])
				q.push(node(dis[v], v));
		}
	}
}

而且第四个点数据输入以后,无法输出答案

2020/5/6 00:45
加载中...