ABC 208
Table of Contents
https://atcoder.jp/contests/abc208
A. Rolling Dice
https://atcoder.jp/contests/abc208/tasks/abc208_a
B. Factorial Yen Coin
https://atcoder.jp/contests/abc208/tasks/abc208_b
C. Fair Candy Distribution
https://atcoder.jp/contests/abc208/tasks/abc208_c
D. Shortest Path Queries 2
https://atcoder.jp/contests/abc208/tasks/abc208_d
ワーシャルフロイドの一番外側の loop が経由地を増やしていることと同義なので、$(A, B)$ 間の距離を更新しつつ、距離が $\infty$ でなければ加算していくことを繰り返せばよい。
void solve() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector dist(N, vll(N, INF));
rep(i, M) {
ll u, v, c;
cin >> u >> v >> c;
u--, v--;
dist[u][v] = c;
}
rep(i, N) dist[i][i] = 0;
ll ans = 0;
rep(k, N) {
rep(i, N) {
rep(j, N) {
if (dist[i][k] + dist[k][j] < dist[i][j]) {
dist[i][j] = dist[i][k] + dist[k][j];
}
if (dist[i][j] != INF) {
ans += dist[i][j];
}
}
}
}
cout << ans << endl;
}
E. Digit Products
https://atcoder.jp/contests/abc208/tasks/abc208_e