이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
/*
const int MOD = ;
inline void mod(int &x) {
if(x >= MOD)
x -= MOD;
}
inline void add(int &x, int y) {
x += y;
mod(x);
}
inline void sub(int &x, int y) {
x += MOD - y;
mod(x);
}
inline void mul(int &x, int y) {
x = (1LL * x * y) % MOD;
}
*/
using namespace std;
const int MAXN = 5000;
vector <int> g[MAXN + 1];
short dp[MAXN + 1][MAXN + 1][2];
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, j, n, m, k;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> k;
for(i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
queue < pair <int, int> > Q;
for(i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
dp[i][j][0] = dp[i][j][1] = -1;
}
Q.push({i, 0});
dp[i][i][0] = 0;
while(Q.size()) {
auto cur = Q.front();
Q.pop();
for(auto it : g[cur.first]) {
if(dp[i][it][cur.second ^ 1] == -1) {
dp[i][it][cur.second ^ 1] = dp[i][cur.first][cur.second] + 1;
Q.push({it, cur.second ^ 1});
}
}
}
}
while(k--) {
int x, y, d;
cin >> x >> y >> d;
if(dp[x][y][d & 1] != -1 && ((dp[x][y][d & 1] < d && g[y].size()) || dp[x][y][d & 1] == d)) {
cout << "TAK\n";
}
else {
cout << "NIE\n";
}
}
//cin.close();
//cout.close();
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... |