?只要没有被松弛,说明这条边是必须边
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#include <vector>
//#define LOCAL
#define INF 0x3f3f3f3f3f3f3f3f
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define PII pair<int, int>
#define int long long
#define ll long long
#define debug(a) cout << #a << "=" << a << endl;
#define all(x) (x).begin(), (x).end()
#define sf(x) scanf("%lld", &(x))
using namespace std;
const int N = 310;
int n, m, d[N][N];
signed main() {
#ifdef LOCAL
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
IOS;
memset(d, 0x3f, sizeof d);
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
int a, b, c;
cin >> a >> b >> c;
d[a][b] = d[b][a] = min(d[a][b], c);
}
for (int k = 1; k <= n; ++k)
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
int ans = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) {
if (d[i][j] == INF)
continue;
bool ok = 0;
for (int k = 1; k <= n; ++k)
if (d[i][j] == d[i][k] + d[k][j]) {
ok = 1;
break;
}
ans += !ok;
}
cout << m - ans / 2 << "\n";
}
|