Sasori @ 2023-07-15 16:04:55
#include<bits/stdc++.h>
using namespace std;
long long n,m,s,a[300][300],b[2000000];
bool k[200000];
void di(){
memset(b,0x3f,sizeof(b));
memset(k,0,sizeof(k));
b[1]=0;
for(int i=1;i<n;i++){int p=0;
for(int j=1;j<=n;j++){
if(!k[j]&&(p==0||b[j]<b[p]))p=j;
k[p]=1;
for(int x=1;x<=n;x++){
b[x]=min(b[x],b[p]+a[p][x]);
}
}
}
}
int main(){
long long q,w,e;
cin>>n>>m>>s;
memset(a,0x3f,sizeof(a));
for(int i=1;i<=n;i++)a[i][i]=0;
for(int i=1;i<=m;i++){
cin>>q>>w>>e;
a[q][w]=min(a[q][w],e);
}
di();
for(int i=1;i<=n;i++)cout<<b[i]<<' ';
return 0;
}```
by ZachekFalse @ 2023-07-15 16:07:17
@Sasori 数组越界
by ZachekFalse @ 2023-07-15 16:07:58
@Sasori 数组开大点
by xixisuper @ 2023-07-15 16:08:07
@Sasori 数组开小了
by xixisuper @ 2023-07-15 16:08:37
@Sasori 这道题应该不能用邻接矩阵
by xixisuper @ 2023-07-15 16:09:08
@Sasori 会炸空间,建议改成用邻接表
by Sasori @ 2023-07-15 16:09:16
@izufei 要开多大?
by ZachekFalse @ 2023-07-15 16:14:03
@Sasori emmm114514试试
by ZachekFalse @ 2023-07-15 16:17:02
@Sasori A了吗
by Sasori @ 2023-07-15 16:21:11
@izufei 空间炸了
by Sasori @ 2023-07-15 16:22:06
@xixisuper 确实炸掉了,我去试一下,谢谢