current position:Home>Folyd

Folyd

2022-08-06 08:53:19ThXe

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;

copyright notice
author[ThXe],Please bring the original link to reprint, thank you.
https://en.chowdera.com/2022/218/202208060847341484.html

Random recommended