# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
472308 |
2021-09-13T11:28:26 Z |
elgamalsalman |
Toll (BOI17_toll) |
C++14 |
|
3000 ms |
7268 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/5 >= v/5) { dp[u] = 1e9; return; }
ll minToll = 1e9;
for (ii edge : adj[u]) {
getToll(edge.fi, v);
if (dp[edge.fi] >= 1e9) 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;
if (a > b) swap(a, b);
getToll(a, b);
cout << (dp[a] >= 1e9 ? -1 : dp[a]) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3096 ms |
7268 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3088 ms |
5328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3096 ms |
7268 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |