社区讨论

【违规紫衫】WA+TLE+MLE

P3371【模板】单源最短路径(弱化版)参与者 5已保存回复 9

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
9 条
当前快照
1 份
快照标识符
@lo1bzrgl
此快照首次捕获于
2023/10/22 18:33
2 年前
此快照最后确认于
2023/11/02 18:55
2 年前
查看原帖
写的floyd,不清楚数据范围多少,MLE一点,还wa了一点,有大佬帮我看看吗?
CPP
//
#define debug
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int Maxn = 5e3 + 1;
const ll INF = 1145141919810;
ll a[Maxn][Maxn];
int n, m, s;

int main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> s;
  for(int i = 1; i <= n; i++){
  	for(int j = 1; j <= n; j++){
  		a[i][j] = INF;
		}
	}
  for(int i = 1; i <= m; i++){
  	int x, y, z;
  	cin >> x >> y >> z;
  	a[x][y] = a[y][x] = z;
	}
	for(int k = 1; k <= n; k++){
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				if(k != i && i != j && j != k && a[i][j] > a[i][k] + a[k][j]){
					a[i][j] = a[i][k] + a[k][j];
				}
			}
		}
	}
	for(int i = 1; i <= n; i++){
		if(i == s){
			cout << "0 ";
		}
		else{
			cout << (a[s][i] == INF ? 2147483647 : a[i][s]) << ' ';
		}
	}
	cout << endl;
	return 0;
}

如果这题有谁知道最大的数据是多少,可以告诉我吗?我反正在题目上没有看到

回复

9 条回复,欢迎继续交流。

正在加载回复...