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>
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int n, m, k;
std::cin >> n >> m >> k;
std::vector<std::vector<int>> adj(n);
for (int i = 0; i < m; ++i) {
int a, b;
std::cin >> a >> b;
--a;
--b;
adj[a].push_back(b);
adj[b].push_back(a);
}
std::vector<std::vector<std::array<short, 2>>> dist(n, std::vector<std::array<short, 2>>(n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
dist[i][j][0] = dist[i][j][1] = 10000;
}
}
auto sp = [&](int st) {
// std::vector<std::array<int, 2>> dist(n, {(int)2e9, (int)2e9});
dist[st][st][0] = 0;
std::queue<std::pair<int, bool>> q;
q.emplace(st, 0);
while (!q.empty()) {
auto [node, par] = q.front();
q.pop();
for (int i : adj[node]) {
if (dist[st][i][!par] > dist[st][node][par] + 1) {
dist[st][i][!par] = dist[st][node][par] + 1;
q.push({i, !par});
}
}
}
};
for (int i = 0; i < n; ++i) {
sp(i);
}
while (k--) {
int s, t, d;
std::cin >> s >> t >> d;
--s;
--t;
if (d >= dist[s][t][d % 2] && (int)adj[s].size() > 0) {
std::cout << "TAK\n";
} else {
std::cout << "NIE\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... |
# | 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... |