???

P1342 请柬

Snow_Dog7 @ 2024-02-17 09:03:14

P1342 请柬 和 P1629 邮递员送信 两道题一样,但是同一份代码P1342只对了一个点,P1629全对 P1342

P1629

不知道错哪里了,求调

#include <bits/stdc++.h>
using namespace std;

int n,m;
vector <pair<int,int>> p1[114514],p2[114514];
int ans;

priority_queue <pair<int,int>> q1;
int d1[114514];
bool v1[114514];

void awa1() {
    memset(d1,0x3f,sizeof(d1));
    d1[1] = 0;
    q1.push(make_pair(0,1));
    while (q1.size()) {
        int x = q1.top().second;q1.pop();
        if (v1[x]) continue;
        v1[x] = 1;
        int siz = p1[x].size();
        for (int i = 0;i < siz;i++) {
            int next = p1[x][i].first,l = p1[x][i].second;
            if (d1[next] > d1[x] + l) {
                d1[next] = d1[x] + l;
                q1.push(make_pair(-d1[next],next));
            }
        }
    }
}

priority_queue <pair<int,int>> q2;
int d2[114514];
bool v2[114514];

void awa2() {
    memset(d2,0x3f,sizeof(d2));
    d2[1] = 0;
    q2.push(make_pair(0,1));
    while (q2.size()) {
        int x = q2.top().second;q2.pop();
        if (v2[x]) continue;
        v2[x] = 1;
        int siz = p2[x].size();
        for (int i = 0;i < siz;i++) {
            int next = p2[x][i].first,l = p2[x][i].second;
            if (d2[next] > d2[x] + l) {
                d2[next] = d2[x] + l;
                q2.push(make_pair(-d2[next],next));
            }
        }
    }
}

int main ( ) {
    cin >> n >> m ;
    for (int i = 1;i <= m;i++) {
        int u,v,w;
        cin >> u >> v >> w ;
        p1[u].push_back(make_pair(v,w));
        p2[v].push_back(make_pair(u,w));
    }

    awa1();
    awa2();

    for (int i = 1;i <= n;i++) {
//      cout << d1[i] << ' ' ;
//      cout << d2[i] << '\n' ;
        ans += d1[i];ans += d2[i];
    }
    cout << ans ;
}

by xiaoshumiao @ 2024-02-17 09:11:50

@Snow_Dog7 long long 开了吗


by Snow_Dog7 @ 2024-02-17 10:02:25

@xiaoshumiao 过了,感谢


by Mr_user @ 2024-02-23 02:33:44

@Snow_Dog7这两道题一样?送信一次只能带一个,这题没说一次只能带一个啊


by Mr_user @ 2024-02-23 02:34:28

@Snow_Dog7 这两道题一样?送信一次只能带一个,这题没说一次只能带一个啊


by Snow_Dog7 @ 2024-02-23 12:32:40

@Mr_user 我看到双倍经验就交了


|