Add a lot more of my solutions.

I don't remember which ones doesn't pass though
This commit is contained in:
2025-09-12 14:51:10 -03:00
parent 2a94def2d6
commit 8b03716512
114 changed files with 14012 additions and 95 deletions

View File

@@ -9,8 +9,8 @@ using namespace std;
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (size_t i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
@@ -77,40 +77,40 @@ int main()
int n, m, q;
cin >> n >> m >> q;
vvl weight(n, vl(n, INT64_MAX >> 1));
vvl floyd(n, vl(n));
ll inf = INT64_MAX >> 1;
vvl graph(n, vl(n, inf));
for (size_t i = 0; i < n; i++) {
weight[i][i] = 0;
rep(i, n) {
graph[i][i] = 0;
}
while (m--) {
ll a, b, c;
cin >> a >> b >> c;
a--, b--;
rmin(weight[a][b], c);
rmin(weight[b][a], c);
rmin(graph[a][b], c);
rmin(graph[b][a], c);
}
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < n; j++) {
floyd[i][j] = weight[i][j];
}
}
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < n; j++) {
for (size_t k = 0; k < n; k++) {
rmin(floyd[j][k], floyd[j][i] + floyd[i][k]);
rep(k, n) {
rep(i, n) {
rep(j, n) {
rmin(graph[i][j], graph[i][k] + graph[k][j]);
}
}
}
while (q--) {
ll a, b;
int a, b;
cin >> a >> b;
a--, b--;
cout << (floyd[a][b] != INT64_MAX >> 1 ? floyd[a][b] : -1) << '\n';
if (graph[a][b] == inf) {
cout << "-1\n";
continue;
}
cout << graph[a][b] << '\n';
}
}