#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define pb push_back
#define fi first
#define si second
#define ar array
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr<<" "<<to_string(H);debug_out(T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
const int INF = 1e18;
int N, M, K, Q, dist[80][80], path[80][80];
signed main() {
fast;
cin >> N >> M;
for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) dist[i][j] = INF, path[i][j] = INF;
for (int i = 1; i <= M; ++i) {
int u, v, c; cin >> u >> v >> c;
dist[u][v] = c;
path[u][v] = 1;
}
cin >> K >> Q;
for (int k = 1; k <= N; ++k) {
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= N; ++j) {
if (i == j) dist[i][j] = 0, path[i][j] = 0;
int new_dist = dist[i][k] + dist[k][j];
int new_path = path[i][k] + path[k][j];
if (new_dist < dist[i][j] && new_path <= K && new_path < path[i][j]) {
dist[i][j] = new_dist;
path[i][j] = new_path;
} else if (new_dist == dist[i][j] && new_path < path[i][j]) {
path[i][j] = new_path;
}
}
}
}
while (Q--) {
int u, v; cin >> u >> v;
if (dist[u][v] == INF) cout << -1 << '\n';
else cout << dist[u][v] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |