이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
vector<int> adjList[MAXN];
short paths[MAXN][MAXN][2];
int main() {
cin.tie(0);ios_base::sync_with_stdio(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
paths[i][j][0] = 32760;
paths[i][j][1] = 32760;
}
paths[i][i][0] = paths[i][i][1] = 0;
}
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
adjList[a].push_back(b);
adjList[b].push_back(a);
}
queue<pair<short, short>> q;
for (int i = 0; i < n; i++) {
q.push({ i, 0 });
while (q.size() > 0) {
short cur = q.front().first;
short num = q.front().second;
q.pop();
for (auto j : adjList[cur]) {
if (paths[i][j][(num + 1) % 2] > num + 1) {
q.push({ j, num + 1 });
paths[i][j][(num + 1) % 2] = num + 1;
}
}
}
}
for (int i = 0; i < k; i++) {
int a, b, c;
cin >> a >> b >> c;
a--;
b--;
if (paths[a][b][c%2] == 32760 || c < paths[a][b][c % 2]) {
cout << "NIE" << endl;
}
else {
cout << "TAK" << endl;
}
}
}
# | 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... |