# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
472341 |
2021-09-13T12:01:15 Z |
elgamalsalman |
Toll (BOI17_toll) |
C++14 |
|
3000 ms |
10172 KB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
ll k, n, m, o, dp[50050];
vvii adj;
void getToll(ll u, ll v) {
//cerr << "// getToll(" << u << ", " << v << ")\n";
if (dp[u] != -1) return;
if (u == v) { dp[u] = 0; return; }
if (u/k >= v/k) { dp[u] = 1e10; return; }
//if (u == 1) cerr << "// check1\n";
ll minToll = 1e10;
for (ii edge : adj[u]) {
//if (u == 1) cerr << "// check2 {" << edge.fi << ", " << edge.se << "}\n";
getToll(edge.fi, v);
if (dp[edge.fi] >= 1e10) continue;
ll currToll = dp[edge.fi] + edge.se;
if (currToll < minToll) minToll = currToll;
}
dp[u] = minToll;
//cerr << "// " << dp[u] << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> k >> n >> m >> o;
adj.assign(n + 20, vii());
for (ll i = 0; i < m; i++) {
ll a, b, t;
cin >> a >> b >> t;
adj[a].push_back({b, t});
}
for (ll i = 0; i < o; i++) {
memset(dp, -1, sizeof dp);
ll a, b;
cin >> a >> b;
getToll(a, b);
cout << (dp[a] >= 1e10 ? -1 : dp[a]) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3077 ms |
7508 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3074 ms |
5444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
716 KB |
Output is correct |
7 |
Correct |
4 ms |
844 KB |
Output is correct |
8 |
Correct |
5 ms |
972 KB |
Output is correct |
9 |
Correct |
4 ms |
844 KB |
Output is correct |
10 |
Correct |
29 ms |
4548 KB |
Output is correct |
11 |
Correct |
128 ms |
7492 KB |
Output is correct |
12 |
Correct |
133 ms |
9092 KB |
Output is correct |
13 |
Correct |
169 ms |
9792 KB |
Output is correct |
14 |
Correct |
146 ms |
8004 KB |
Output is correct |
15 |
Correct |
81 ms |
4984 KB |
Output is correct |
16 |
Correct |
69 ms |
4904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
716 KB |
Output is correct |
7 |
Correct |
4 ms |
844 KB |
Output is correct |
8 |
Correct |
5 ms |
972 KB |
Output is correct |
9 |
Correct |
4 ms |
844 KB |
Output is correct |
10 |
Correct |
29 ms |
4548 KB |
Output is correct |
11 |
Correct |
128 ms |
7492 KB |
Output is correct |
12 |
Correct |
133 ms |
9092 KB |
Output is correct |
13 |
Correct |
169 ms |
9792 KB |
Output is correct |
14 |
Correct |
146 ms |
8004 KB |
Output is correct |
15 |
Correct |
81 ms |
4984 KB |
Output is correct |
16 |
Correct |
69 ms |
4904 KB |
Output is correct |
17 |
Correct |
1843 ms |
7896 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
21 |
Correct |
1 ms |
588 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
49 ms |
716 KB |
Output is correct |
24 |
Correct |
69 ms |
880 KB |
Output is correct |
25 |
Correct |
88 ms |
940 KB |
Output is correct |
26 |
Correct |
81 ms |
892 KB |
Output is correct |
27 |
Correct |
126 ms |
4460 KB |
Output is correct |
28 |
Correct |
2543 ms |
9540 KB |
Output is correct |
29 |
Correct |
2966 ms |
10172 KB |
Output is correct |
30 |
Correct |
1727 ms |
7736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3077 ms |
7508 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |