Skip to content

Commit b6c6e60

Browse files
committed
atcoder/abc051D (feedback from editorial)
1 parent 4643e1e commit b6c6e60

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

atcoder/abc051/D/main.cpp

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,35 @@ using ll = long long;
66
const int inf = 1e7;
77
int N, M;
88
vector<vector<int>> G;
9-
vector<vector<int>> P;
10-
vector<vector<bool>> U;
11-
12-
void fill(int i, int j) {
13-
if (P[i][j] == N) {
14-
U[j][j] = U[i][j] = true;
15-
return;
16-
}
17-
int k = P[i][j];
18-
fill(i, k);
19-
fill(k, j);
20-
}
9+
vector<vector<int>> O;
2110

2211
int solve() {
23-
P.assign(N, vector<int>(N, N));
24-
U.assign(N, vector<bool>(N, false));
12+
// COPY
13+
O = G;
2514

2615
for (int k = 0; k < N; ++k) {
2716
for (int i = 0; i < N; ++i) {
2817
for (int j = 0; j < N; ++j) {
2918
if (G[i][k] == inf || G[k][j] == inf) continue;
3019
if (G[i][k] + G[k][j] < G[i][j]) {
3120
G[i][j] = G[i][k] + G[k][j];
32-
P[i][j] = k;
3321
}
3422
}
3523
}
3624
}
3725

26+
int ans = 0;
3827
for (int i = 0; i < N; ++i) {
39-
for (int j = 0; j < N; ++j) {
40-
fill(i, j);
41-
}
42-
}
43-
44-
int e = 0;
45-
for (int i = 0; i < N; ++i) {
46-
for (int j = 0; j < N; ++j) {
47-
if (i != j && U[i][j]) ++e;
28+
for (int j = i + 1; j < N; ++j) {
29+
if (i == j || O[i][j] == inf) continue;
30+
bool use = false;
31+
for (int s = 0; s < N; ++s) {
32+
if (G[s][i] + O[i][j] == G[s][j]) use = true;
33+
}
34+
if (!use) ++ans;
4835
}
4936
}
50-
return M - (e / 2);
37+
return ans;
5138
}
5239

5340
int main() {
@@ -56,6 +43,7 @@ int main() {
5643

5744
cin >> N >> M;
5845
G.assign(N, vector<int>(N, inf));
46+
for (int i = 0; i < N; ++i) G[i][i] = 0;
5947
for (int i = 0; i < M; ++i) {
6048
int a, b, c;
6149
cin >> a >> b >> c;

0 commit comments

Comments
 (0)