文章

34

粉丝

0

获赞

142

访问

4.5k

头像
最短路径问题 这题这里的数据有点弱,我之前写的代码在牛客那里ac不了在这里可以ac 题解:
P1344 浙江大学机试题
发布于2026年3月14日 15:33
阅读数 99

错误:
 

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 9;
struct Node{
    int v, w, c;
    bool operator < (const Node &other) const{
        if(w != other.w) return w > other.w;
        if(w == other.w) return c > other.c;
        return v > other.v;
    }
};
vector<Node> g[N];
int dis[N]; int cost[N];
bool vis[N];

int main() {
	int n, m;
	while(cin >> n >> m)
	{
        for(int i = 1; i <= n; i++) g[i].clear();
	    if(n == 0 && m == 0) break;
	    memset(dis, 0x3f, sizeof(dis));
	    memset(cost, 0x3f, sizeof(cost));
	    memset(vis, false, sizeof(vis));
	    for(int i = 1; i <= m; i ++)
	    {
	        int u, v, w, c; cin >> u >> v >> w >> c;
	        g[u].push_back({v, w, c}); g[v].push_back({u, w, c});
	    }
	    int s, e; cin >> s >> e;
	    priority_queue<Node> pq; pq.push({s, 0, 0});
	    dis[s] = 0; vis[s] = true; cos...
登录查看完整内容


登录后发布评论

1 条评论
liux662
2026年3月14日 15:34

链接:https://www.nowcoder.com/practice/e372b623d0874ce2915c663d881a3ff2?tpId=63&tqId=29599&tPage=2&ru=/kaoyan/retest/9001&qru=/ta/zju-kaoyan/question-ranking

赞(0)
回复给: