#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;
}
}
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
paths[a][a][0] = 0;
paths[b][b][0] = 0;
adjList[a].push_back(b);
adjList[b].push_back(a);
}
queue<pair<int, int>> q;
for (int i = 0; i < n; i++) {
q.push({ i, 0 });
while (q.size() > 0) {
int cur = q.front().first;
int num = q.front().second;
q.pop();
for (auto j : adjList[cur]) {
if (paths[i][j][(num + 1) % 2] == -1 || 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;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
2392 ms |
5008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
2416 ms |
4984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
640 KB |
Output is correct |
2 |
Correct |
1 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
2688 KB |
Output is correct |
2 |
Correct |
7 ms |
1408 KB |
Output is correct |
3 |
Correct |
28 ms |
3456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
4352 KB |
Output is correct |
2 |
Correct |
35 ms |
6280 KB |
Output is correct |
3 |
Correct |
95 ms |
6520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
226 ms |
15480 KB |
Output is correct |
2 |
Correct |
26 ms |
5760 KB |
Output is correct |
3 |
Correct |
410 ms |
24312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2903 ms |
28312 KB |
Output is correct |
2 |
Correct |
46 ms |
24192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3062 ms |
81528 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3096 ms |
100984 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3094 ms |
100472 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |