#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;}
auto operator<<(auto &o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";}
#define debug(X) cerr << "["#X"]: " << X << '\n';
#else
#define debug(X) ;
#endif
#define ll long long
#define all(v) (v).begin(), (v).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);++i)
#define ROF(i,r,l) for(int i=(r);i>=(l);--i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) int(x.size())
#define fi first
#define se second
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int k, n, m, o;
cin >> k >> n >> m >> o;
vector<vector<pair<int, int>>> G(n);
REP(i, m) {
int a, b, t;
cin >> a >> b >> t;
G[a].push_back({b, t});
}
constexpr int inf = 1e9;
vector dp(n, vector(n, inf));
REP(j, n) {
dp[j][j] = 0;
ROF(i, n-1, 0) {
for (auto w : G[i]) {
dp[i][j] = min(dp[i][j], w.se+dp[w.fi][j]);
}
}
}
REP(i, o) {
int a, b;
cin >> a >> b;
cout << (dp[a][b]==inf?-1:dp[a][b]) << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
179 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
181 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
4328 KB |
Output is correct |
7 |
Correct |
6 ms |
4308 KB |
Output is correct |
8 |
Correct |
10 ms |
4436 KB |
Output is correct |
9 |
Correct |
8 ms |
4308 KB |
Output is correct |
10 |
Runtime error |
170 ms |
524288 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
4328 KB |
Output is correct |
7 |
Correct |
6 ms |
4308 KB |
Output is correct |
8 |
Correct |
10 ms |
4436 KB |
Output is correct |
9 |
Correct |
8 ms |
4308 KB |
Output is correct |
10 |
Runtime error |
170 ms |
524288 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
179 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |