lijunxi1 @ 2023-07-11 17:50:10
#include<bits/stdc++.h>
using namespace std;
bool zg[10005];
struct aa
{
int x,p;
};
vector<vector<aa> >a;
struct bb
{
int x,y,p;
bool operator <(const bb &n)const
{
return n.p<p;
}
}b,c;
int n,m,s,t,s1,s2,s3;
void bfs()
{
memset(zg,0,sizeof zg);
if(s==t)
{
cout<<"0 ";
return;
}
priority_queue<bb>q;
zg[s]=1;
b.x=s;
for (int i=1;i<=a[s][0].p;i++)
{
b.y=a[s][i].x;
b.p=a[s][i].p;
q.push(b);
}
while(!q.empty())
{
b=q.top();
q.pop();
zg[b.y]=1;
c.x=b.y;
if (b.y==t)
{
cout<<b.p<<" ";
return;
}
for (int i=1;i<=a[c.x][0].p;i++)
{
c.y=a[c.x][i].x;
c.p=a[c.x][i].p+b.p;
if (zg[c.y]==0)q.push(c);
}
}
cout<<int(pow(2,31)-1)<<" ";
}
int main ( )
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n>>m>>s;a.resize(100005);
for (int i=1;i<=n;i++)a[i].resize(200005);
for (int i=1;i<=m;i++)
{
cin>>s1>>s2>>s3;
a[s1][0].p++;
a[s1][a[s1][0].p].x=s2;
a[s1][a[s1][0].p].p=s3;
a[s2][0].p++;
a[s2][a[s2][0].p].x=s1;
a[s2][a[s2][0].p].p=s3;
}
for (int i=1;i<=n;i++)
{
t=i;
bfs();
}
}
by lijunxi1 @ 2023-07-11 17:51:50
void bfs()
{
}
=
void Dijkstra()
{
}
by lijunxi1 @ 2023-07-11 17:52:06
是Dijkstra
by cq_zry @ 2023-07-11 18:17:24
@lijunxi1 你dj套用地好奇怪,跑一遍就能求所有单元最短路了
by Steve_xh @ 2023-07-11 18:18:07
@lijunxi1 最好不要用vector,二维数组会更好
by undefined_Ryan @ 2023-07-11 18:36:00
@Steve_xh 二维数组空间也要炸,把边数总和开到单个上变成二维会出问题,最好vector+push_back
by undefined_Ryan @ 2023-07-11 18:36:29
100000*200000的存边