CE求助

回复帖子

@墨石 2021-05-04 21:02 回复

编译信息 编译失败

        No valid executable file was produced by the compiler

/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax collect2: 错误:ld 返回 1

@墨石 2021-05-04 21:05 回复 举报
#include <iostream>
#include <cstdint>

using namespace std;

const int N = 100005;
const int INF = INT32_MAX / 2;

int n, m;
int w[N][N];
int dis[N], bj[N];
int s;

void bg()
{
    for (int i = 1; i <= N - 5; i++)
    {
        for (int j = 1; j <= N - 5; j++)
        {
            if (i == j)
            {
                continue;
            }

            w[i][j] = INF;
        }
    }
}

void d(int b)
{
    for (int i = 1; i <= n; i++)
    {
        dis[i] = w[b][i];
    }

    dis[b] = 0;
    bj[b] = 1;

    int i = n;
    while (--i)
    {
        int mi = -1;
        int mn = INF;

        for (int j = 1; j <= n; j++)
        {
            if (bj[j] || dis[j] == INF)
            {
                continue;
            }

            if (dis[j] < mn)
            {
                mn = dis[j];
                mi = j;
            }
        }

        if (mi == -1)
        {
            break;
        }

        bj[mi] = 1;

        for (int j = 1; j <= n; j++)
        {
            if (bj[j] || dis[mi] + w[mi][j] > dis[j])
            {
                continue;
            }

            dis[j] = w[mi][j] + dis[mi];
        }
    }
}

int main()
{
    bg();

    cin >> n >> m >> s;

    for (int i = 1; i <= m; i++)
    {
        int ta, tb, tl;
        cin >> ta >> tb >> tl;

        w[ta][tb] = tl;
    }

    d(s);

    for (int i = 1; i <= n; i++)
    {
        if (dis[i] != INF)
        {
            cout << dis[i] << " ";
        }
        else
        {
            cout << -1 << " ";
        }
    }

    return 0;
}

迪杰斯特拉最短路

反馈
如果你认为某个帖子有问题,欢迎向洛谷反馈,以帮助更多的同学。



请具体说明理由,以增加反馈的可信度。