This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, u; cin >> n >> m >> u;
vector <vector<pair<int, int>>> edges;
vector<pair<int, int>> empty;
for (int i= 0; i < n+5; i++) edges.push_back(empty);
for (int i = 0; i < m; i++) {
int x, y, z; cin >> x >> y >> z;
edges[x].push_back({y, z});
edges[y].push_back({x, z});
}
int ans[n+5][n+5];
for (int i = 1; i <= n; i++) {
//dijkstra from here?
for (int j =1; j <= n; j++) ans[i][j] = 1000000500;
ans[i][i] = 0;
priority_queue <pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
pq.push({0, i});
while (pq.size() > 0) {
auto tmp = pq.top();
pq.pop();
if (tmp.first > ans[i][tmp.second]) continue;
ans[i][tmp.second] = tmp.first;
for (auto k:edges[tmp.second]) {
if (max(tmp.first, k.second) < ans[i][k.first]) {ans[i][k.first] = max(tmp.first, k.second); pq.push({max(tmp.first, k.second), k.first});}
}
}
}
while (u--) {
int x, y, z; cin >> x >> y >> z;
if (ans[x][y] > z) cout << "NE" << '\n';
else cout << "TAIP" << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |