이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
d = std::min(d, 9998 + d % 2);
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... |