团体程序设计天梯赛 紧急救援(21/25)

就有些怪,在acwing里一道类似的题是过的,但是在天梯赛里,最后一种情况就过不了,还有一点很怪的就是,我用这种字符串记录路径的方式在pta上会报g::_M_construct null not valid,查了一次也没看懂,最后直接把它跳过去输出后面的才过的样例 

#include <bits/stdc++.h>
using namespace std;
int n, m, s, d;
int que[505], lujing[505];
bool jud[505];
int before[505];
vector<pair<int, int>> lu[505];
struct item
{
    int bianhao;
    int val;
    int num;
    int numpue;
    string luu;
};
bool operator<(item a, item b)
{
    if (a.val > b.val)
        return true;
    else if (a.val == b.val)
        return a.numpue < b.numpue;
    else
        return false;
}
int main()
{
    cin >> n >> m >> s >> d;
    for (int i = 0; i < n; i++)
        cin >> que[i];
    while (m--)
    {
        int a, b, c;
        cin >> a >> b >> c;
        lu[a].push_back({b, c});
        lu[b].push_back({a, c});
    }

    item beginn = {s, 0, 0, que[s], "" + (char)('0' + s)};
    before[s] = -1;
    priority_queue<item> q;
    q.push(beginn);
    while (!q.empty())
    {
        item t = q.top();
        if (t.bianhao == d)
            break;
        q.pop();
        jud[t.bianhao] = 1;
        for (int i = 0; i < lu[t.bianhao].size(); i++)
        {
            if (!jud[lu[t.bianhao][i].first])
            {
                q.push({lu[t.bianhao][i].first, t.val + lu[t.bianhao][i].second, t.num + 1, t.numpue + que[lu[t.bianhao][i].first], t.luu + (char)('0' + t.bianhao)});
            }
        }
    }
    item ans = q.top();
    int num = 1;
    q.pop();
    while (!q.empty())
    {
        if (q.top().bianhao == d && q.top().val == ans.val)
            num++;
        else if (q.top().bianhao == d)
            break;
        q.pop();
    }
    cout << num << ' ' << ans.numpue << '\n';
    for (int i = 30; i < ans.luu.size(); i++)
    {
        cout << ans.luu[i] << ' ';
    }
    cout << d;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值