#include <bits/stdc++.h>
using namespace std;
struct Edge {
int v, w;
};
const int MXN = 5e4+5;
const int INF = 1e9;
int k, n, m, o;
vector<Edge> adj[MXN];
int dist[MXN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> k >> n >> m >> o;
for(int i = 0; i < m; i++) {
int u, v, w; cin >> u >> v >> w;
adj[u].push_back({v, w});
}
for(int _ = 0; _ < o; _++) {
fill(dist, dist+n, INF);
int a, b; cin >> a >> b;
dist[a] = 0;
for(int i = a; i < b; i++) {
for(auto e : adj[i]) {
dist[e.v] = min(dist[e.v], dist[i]+e.w);
}
}
if(dist[b] == INF) cout << "-1\n";
else cout << dist[b] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2731 ms |
4224 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
4 ms |
1512 KB |
Output is correct |
6 |
Correct |
5 ms |
1620 KB |
Output is correct |
7 |
Correct |
4 ms |
1492 KB |
Output is correct |
8 |
Correct |
2768 ms |
3908 KB |
Output is correct |
9 |
Correct |
2536 ms |
3828 KB |
Output is correct |
10 |
Correct |
328 ms |
1820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3035 ms |
4284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1504 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
2 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
2 ms |
1492 KB |
Output is correct |
7 |
Correct |
2 ms |
1516 KB |
Output is correct |
8 |
Correct |
3 ms |
1636 KB |
Output is correct |
9 |
Correct |
3 ms |
1508 KB |
Output is correct |
10 |
Correct |
48 ms |
3796 KB |
Output is correct |
11 |
Correct |
68 ms |
3916 KB |
Output is correct |
12 |
Correct |
96 ms |
4732 KB |
Output is correct |
13 |
Correct |
105 ms |
5028 KB |
Output is correct |
14 |
Correct |
77 ms |
4396 KB |
Output is correct |
15 |
Correct |
47 ms |
3540 KB |
Output is correct |
16 |
Correct |
49 ms |
3604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1504 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
2 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
2 ms |
1492 KB |
Output is correct |
7 |
Correct |
2 ms |
1516 KB |
Output is correct |
8 |
Correct |
3 ms |
1636 KB |
Output is correct |
9 |
Correct |
3 ms |
1508 KB |
Output is correct |
10 |
Correct |
48 ms |
3796 KB |
Output is correct |
11 |
Correct |
68 ms |
3916 KB |
Output is correct |
12 |
Correct |
96 ms |
4732 KB |
Output is correct |
13 |
Correct |
105 ms |
5028 KB |
Output is correct |
14 |
Correct |
77 ms |
4396 KB |
Output is correct |
15 |
Correct |
47 ms |
3540 KB |
Output is correct |
16 |
Correct |
49 ms |
3604 KB |
Output is correct |
17 |
Correct |
947 ms |
3880 KB |
Output is correct |
18 |
Correct |
2 ms |
1496 KB |
Output is correct |
19 |
Correct |
2 ms |
1500 KB |
Output is correct |
20 |
Correct |
1 ms |
1492 KB |
Output is correct |
21 |
Correct |
1 ms |
1492 KB |
Output is correct |
22 |
Correct |
1 ms |
1500 KB |
Output is correct |
23 |
Correct |
11 ms |
1576 KB |
Output is correct |
24 |
Correct |
13 ms |
1492 KB |
Output is correct |
25 |
Correct |
21 ms |
1660 KB |
Output is correct |
26 |
Correct |
19 ms |
1620 KB |
Output is correct |
27 |
Correct |
840 ms |
3884 KB |
Output is correct |
28 |
Correct |
1168 ms |
4916 KB |
Output is correct |
29 |
Correct |
1261 ms |
5088 KB |
Output is correct |
30 |
Correct |
1049 ms |
4652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2731 ms |
4224 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
4 ms |
1512 KB |
Output is correct |
6 |
Correct |
5 ms |
1620 KB |
Output is correct |
7 |
Correct |
4 ms |
1492 KB |
Output is correct |
8 |
Correct |
2768 ms |
3908 KB |
Output is correct |
9 |
Correct |
2536 ms |
3828 KB |
Output is correct |
10 |
Correct |
328 ms |
1820 KB |
Output is correct |
11 |
Execution timed out |
3035 ms |
4284 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |