This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0);
const int MAXN = 5005;
vector<int> adjList[MAXN];
int paths[MAXN][MAXN][2];
void bfs(int p) {
queue< pair<int, int> > q;
q.push(make_pair(p, 0));
while (!q.empty()) {
int cn = q.front().first;
int cd = q.front().second;
q.pop();
for (int i = 0; i<adjList[cn].size(); i++) {
int nn = adjList[cn][i];
if (paths[p][nn][(cd + 1) % 2]>cd + 1) {
paths[p][nn][(cd + 1) % 2] = cd + 1;
q.push(make_pair(nn, cd + 1));
}
}
}
}
int main() {
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] = INT_MAX;
paths[i][j][1] = INT_MAX;
}
}
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;
}
}
}
*/
bfs(i);
}
for (int i = 0; i < k; i++) {
int a, b, c;
cin >> a >> b >> c;
a--;
b--;
if (paths[a][b][c%2] == INT_MAX || c < paths[a][b][c % 2]) {
cout << "NIE" << endl;
}
else {
cout << "TAK" << endl;
}
}
}
Compilation message (stderr)
mor.cpp: In function 'void bfs(int)':
mor.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i = 0; i<adjList[cn].size(); i++) {
| ~^~~~~~~~~~~~~~~~~~~
# | 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... |