有没有好心人帮我把我的代码提交一下,悬关
查看原帖
有没有好心人帮我把我的代码提交一下,悬关
518500
Ted_LightningTechG_楼主2024/7/10 15:13

Rt.

ybt1486黑暗城堡的题目

能不能帮我把我的代码提交到LOJ,并把错误测试点输入输出发给我

#include<bits/stdc++.h>
#define int long long
struct node{
	int dis, d;
	int u;
}pnt[1005];
int N, M, u, v, l;
int s[1005][1005];
int Ans = 1;
const int mod = 2147483647;
struct cmp {
	bool operator()(node x, node y) {
		return x.dis > y.dis;
	}
};
std::priority_queue<node, std::vector<node>, cmp> hp;
std::vector<int> G[1005];
signed main() {
	std::cin >> N >> M;
	while(M --> 0) {
		std::cin >> u >> v >> l;
		G[u].push_back(v), G[v].push_back(u), s[u][v] = s[v][u] = l;
	}
	pnt[1] = {0, 1, 1};
	for(int i = 2; i <= N; i ++) pnt[i].dis = mod, pnt[i].u = i;
	hp.push(pnt[1]);
	for(int i = 1; i < N; i ++) {
		node g = hp.top();
		hp.pop();
		for(auto son : G[g.u]) {
			if(pnt[son].dis > g.dis + s[g.u][son]) pnt[son].dis = g.dis + s[g.u][son], hp.push(pnt[son]), pnt[son].d = 1;
			else if(pnt[son].dis == g.dis + s[g.u][son]) pnt[son].d ++, pnt[son].d %= mod;
		}	
	}
	for(int i = 2; i <= N; i ++) Ans = Ans * pnt[i].d % mod;
	std::cout << Ans;
	return 0;
}

大好人,救救我,悬关!

2024/7/10 15:13
加载中...