struct Folyd {
ll mp[N][N];//i-j>最短路
ll way[N][N];//i->j有多少条不同的最短路
double ans[N];
int n, m;
void init()
{
memset(mp, 0x3f, sizeof mp);
cin >> n >> m;
while (m--)
{
int a, b, c; cin >> a >> b >> c;
mp[a][b] = c;
mp[b][a] = c;
way[a][b] = 1;
way[b][a] = 1;
}
}
void folyd()
{
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for (int j = 1; j <= n; j++)
{
if (i != j && j != k && i != k)
{
if (mp[i][j] == mp[i][k] + mp[k][j])
{
way[i][j] += way[i][k] * way[k][j];
}
else if (mp[i][j] > mp[i][k] + mp[k][j])
{
way[i][j] = way[i][k] * way[k][j];
mp[i][j] = mp[i][k] + mp[k][j];
}
}
}
}
}folyd;
Folyd
最新推荐文章于 2024-09-03 11:25:36 发布