Submission #1106124

#TimeUsernameProblemLanguageResultExecution timeMemory
1106124atomAutobus (COCI22_autobus)C++17
0 / 70
3 ms592 KiB
#include "bits/stdc++.h" // @JASPER'S BOILERPLATE using namespace std; using ll = long long; #ifdef JASPER #include "debug.h" #else #define debug(...) 166 #endif const int N = 75; const ll INF = 1e18; ll d[N][N]; int cnt[N][N]; signed main() { cin.tie(0) -> sync_with_stdio(0); #ifdef JASPER freopen("in2", "r", stdin); #endif int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { d[i][j] = INF; if (i == j) d[i][j] = 0; } } vector <array <int, 3>> edges; for (int i = 1; i <= m; ++i) { int u, v, w; cin >> u >> v >> w; edges.push_back({u, v, w}); } int K, q; cin >> K >> q; for (int i = 0; i < m; ++i) { auto [u, v, w] = edges[i]; if (w < d[u][v]) { d[u][v] = w; cnt[u][v] = 1; } } for (int k = 1; k <= n; ++k) { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if (d[i][k] + d[k][j] < d[i][j] && cnt[i][k] + cnt[k][j] <= K) { d[i][j] = d[i][k] + d[k][j]; cnt[i][j] = cnt[i][k] + cnt[k][j]; } else if (d[i][k] + d[k][j] == d[i][j] && cnt[i][k] + cnt[k][j] <= K) { cnt[i][j] = min(cnt[i][j], cnt[i][k] + cnt[k][j]); } } } } // cout << d[1][4] << "\n"; for (int _q = 1; _q <= q; ++_q) { int x, y; cin >> x >> y; if (d[x][y] == INF || cnt[x][y] > K) { cout << "-1\n"; } else cout << d[x][y] << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...