이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1'000'000'007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int nodes, edges; cin >> nodes >> edges;
vector<pair<pair<int, int>, int>> edgelist(edges);
for (int i = 0; i < edges; i++) {
int a, b, t; cin >> a >> b >> t;
edgelist[i] = { {a, b},t };
}
int maxbus, queries; cin >> maxbus >> queries;
maxbus = min(maxbus, nodes - 1);
int dist[71][71][71];
for (int i = 0; i < 71; i++)
for (int j = 0; j < 71; j++)
for (int k = 0; k < 71; k++)
dist[i][j][k] = inf;
for (int i = 1; i <= nodes; i++) {
dist[i][i][0] = 0;
for (int j = 1; j <= maxbus; j++)
for (auto e : edgelist) {
int a = e.first.first, b = e.first.second, t = e.second;
dist[i][b][j] = min(dist[i][b][j], dist[i][a][j - 1] + t);
}
}
for (int i = 0; i < queries; i++) {
int a, b; cin >> a >> b;
int ans = inf;
for (int j = 0; j <= maxbus; j++) ans = min(ans, dist[a][b][j]);
cout << ((ans == inf) ? -1 : ans) << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |