https://atcoder.jp/contests/abc051/tasks/abc051_d
// https://atcoder.jp/contests/abc051/tasks/abc051_d
// 一条边不含于任何一条最短路中, 当且仅当w[i][j] > dist[i][j], 即存在一条最短路的权比这条边的权小
#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 110, INF = 0x3f3f3f3f;
int g[N][N]; // Floyd
int f[N][N]; // 边权备份
int n, m;
void solv()
{
cin >> n >> m;
int a, b, c;
// 初始化
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++)
if (i != j) g[i][j] = INF;
// 读入
for (int i = 1; i <= m; i ++)
{
cin >> a >> b >> c;
g[a][b] = g[b][a] = c;
}
// 备份边权
memcpy(f, g, sizeof f);
// floyed
for (int k = 1; k <= n; k ++)
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++)
if (g[i][k] + g[k][j] < g[i][j]) g[i][j] = g[i][k] + g[k][j];
// count
int cnt = 0;
for (int i = 1; i <= n; i ++)
for (int j = i + 1; j <= n; j ++)
{
// cout << i << ',' << j << " " << g[i][j] << f[i][j] << endl;
if (f[i][j] < INF && f[i][j] > g[i][j]) cnt ++;
}
cout << cnt << endl;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T = 1;
// cin >> T;
while (T --)
{
solv();
}
return 0;
}
标签:typedef,contests,int,tasks,abc051,include
From: https://www.cnblogs.com/o2iginal/p/17495605.html