# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1111392 |
2024-11-12T08:06:36 Z |
jmuzhen |
Drivers (BOI24_drivers) |
C++17 |
|
1 ms |
504 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
using ii = pair<int, int>;
vector<vector<ii>> adj;
int n, m, u;
/* observation: abs(dist(a, x) - dist(b, x)) <= dist(a, b) <= dist(a, x) + dist(b, x)
* in fact, only the left half is useful.
* The answer is YES, iff we can find some abs(dist(a, x) - dist(b, x)) <= p (the query value).
*/
void dijkstra(int src, vector<int>& dist) {
priority_queue<ii, vector<ii>, greater<ii>> pq;
dist[src] = 0; pq.push({0, src});
while (!pq.empty()) {
auto [d, u] = pq.top(); pq.pop();
if (d > dist[u]) continue;
for (auto [v, w] : adj[u]) {
if (dist[u] + w < dist[v]) {
dist[v] = dist[u] + w;
pq.push({dist[v], v});
}
}
}
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m >> u;
// all nodes are 1-indexed.
adj = vector<vector<ii>>(n+1, vector<ii>());
for (int i = 0; i < m; i++) {
int a, b, t; cin >> a >> b >> t;
adj[a].push_back({b, t});
adj[b].push_back({a, t});
}
// dijkstra
vector<vector<int>> all_dist(n+1, vector<int>());
for (int i = 1; i <= n; i++) {
vector<int> dist(n+1, 1e15);
dijkstra(i, dist);
all_dist[i] = dist;
}
// queries
while (u--) {
int a, b, p ; cin >> a >> b >> p;
assert(all_dist[a][b] == all_dist[b][a]);
if (all_dist[a][b] <= p) {
cout << "TAIP\n";
}
else {
cout << "NE\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |