이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
const int MAX = 5005;
vector<int> G[MAX];
short D[MAX][MAX][2];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int N, M, Q;
cin >> N >> M >> Q;
for (int i = 1; i <= M; ++i) {
int a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
memset(D, 0x3f, sizeof(D));
for (int i = 1; i <= N; ++i) {
queue<pii> Q;
Q.emplace(i, 0);
D[i][i][0] = 0;
while (!Q.empty()) {
auto [cur, p] = Q.front(); Q.pop();
for (int next : G[cur]) {
int np = p ^ 1;
if (D[i][next][np] < 11111) continue;
D[i][next][np] = D[i][cur][p] + 1;
Q.emplace(next, np);
}
}
}
while (Q--) {
int a, b, c;
cin >> a >> b >> c;
int d = D[a][b][c & 1];
bool ok = d <= c && d < 11111;
if (c % 2 == 0) ok &= !G[a].empty();
cout << (ok ? "TAK" : "NIE") << '\n';
}
return 0;
}
# | 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... |