#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 50001;
vector <pair <int, int>> adj[maxn];
ll dis[maxn];
int processed[maxn];
queue <int> modified;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int K, N, M, O;
cin >> K >> N >> M >> O;
for (int i = 0; i < M; i++) {
int a, b, t;
cin >> a >> b >> t;
adj[a].push_back({b, t});
}
fill(dis, dis + N + 1, 1e18);
for (int o = 1; o <= O; o++) {
int st, ed;
cin >> st >> ed;
dis[st] = 0;
priority_queue <pair <ll, int>> pq;
modified.push(st);
pq.push({0, st});
while (!pq.empty()) {
int s = pq.top().second;
pq.pop();
if (processed[s] == o)
continue;
processed[s] = o;
for (auto i : adj[s]) {
if (dis[i.first] > dis[s] + i.second) {
if (dis[i.first] == 1e18)
modified.push(i.first);
dis[i.first] = dis[s] + i.second;
pq.push({-dis[i.first], i.first});
}
}
}
if (dis[ed] == 1e18)
dis[ed] = -1;
cout << dis[ed] << '\n';
while (!modified.empty()) {
dis[modified.front()] = 1e18;
modified.pop();
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3042 ms |
4176 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3061 ms |
3780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3042 ms |
4176 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |