이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector <int> adj[5001];
int dist[5001][5001][2];
void bfs (int x) {
queue <pair <int, int>> cur;
cur.push({x, 0});
int cnt = 0;
while (!cur.empty()) {
int u = cur.size();
while (u--) {
auto k = cur.front();
cur.pop();
if (k.second == 0) {
dist[x][k.first][0] = cnt;
for (auto j : adj[k.first]) {
if (dist[x][j][1] != -1) continue;
cur.push({j, 1});
}
} else {
dist[x][k.first][1] = cnt;
for (auto j : adj[k.first]) {
if (dist[x][j][0] != -1) continue;
cur.push({j, 0});
}
}
}
cnt++;
}
}
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
memset(dist, -1, sizeof(dist));
while (m--) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for (int i = 1; i <= n; i++) {
bfs(i);
}
while (k--) {
int a, b, c;
cin >> a >> b >> c;
if (dist[b][c][a&1] != -1 && dist[b][c][a&1] <= a) {
cout << "TAK\n";
} else {
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... |