求调wa 1 、3、 4

P4779 【模板】单源最短路径(标准版)

cat152 @ 2024-03-25 17:35:13

#include <iostream>  
#include <vector>
#include <map>
#include <queue>

using namespace std;
constexpr int max_num = (int)1e5 + 5;
constexpr int uF = 0x7fffffff;
int n, m, s;

struct node
{
    int d;
    int v;
    bool operator<(const node& value) const
    {
        return v > value.v;
    }

    node(int a, int b)
    {
        d = a;
        v = b;
    }
};

priority_queue<node> que;
vector<pair<int,int>> vmap[max_num];
int ans[max_num];
bool tvis[max_num] = {false};
//bool tk[max_num];

void bfs()
{
    while (!que.empty())
    {
        int c = que.top().d;
        que.pop();
        /*if (tk[c])   continue;
        tk[c] = true;*/
        for (auto it : vmap[c])
        {
            if ( ans[c] + it.second < ans[it.first])
            {
                ans[it.first] = ans[c] + it.second;
                if (!tvis[it.first])
                {
                    que.push(node(it.first, ans[it.first]));
                    tvis[it.first] = true;
                }
            }
        }
    }
}

int main() {
    int x, y, v;
    cin >> n >> m >> s;
    for (int i = 1; i <= n; i++)
    {
        ans[i] = uF;
    }
    ans[s] = 0;
    for (int i = 1; i <= m; i++)
    {
        cin >> x >> y >> v;
        vmap[x].push_back(pair<int,int>(y,v));
    }
    que.push(node(s,0));
    bfs();
    for (int i = 1; i < n; i++)
    {
        cout << ans[i] << " ";
    }
    cout << ans[n] << endl;
    return 0;
}

by cat152 @ 2024-03-25 18:16:32

已过

if (!tvis[it.first])
                {
                    que.push(node(it.first, ans[it.first]));
                    tvis[it.first] = true;
                }

这里的问题


by I_sland @ 2024-04-04 14:03:55

借楼警钟,我也WA1,3,4,是因为我按无向边算了


|