#include <bits/stdc++.h>
#define FOR(i,x,n) for(int i=x; i<n; i++)
#define F0R(i,n) FOR(i,0,n)
#define ROF(i,x,n) for(int i=n-1; i>=x; i--)
#define R0F(i,n) ROF(i,0,n)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define FILL(a, b) memset(a, b, sizeof(a));
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
const int MAXN = 5000+2;
int n, m, k, u, v, to, st, fn, len;
VI adj[MAXN];
short int fastest_route[MAXN][MAXN][2];
void Input() {
cin >> n >> m >> k;
F0R (i, m) {
cin >> u >> v;
adj[--u].pb(--v);
adj[v].pb(u);
}
}
void Bfs(int now_on) {
queue <PII> keep;
int place, dep;
keep.push({now_on, 0});
while (!keep.empty()) {
place = keep.front().F;
dep = keep.front().S;
keep.pop();
dep++;
F0R (i, adj[place].size()) {
to = adj[place][i];
if (fastest_route[now_on][to][dep & 1] == 0) {
fastest_route[now_on][to][dep & 1] = dep;
keep.push({to, dep});
}
}
}
return;
}
int main() {
IOS;
Input();
F0R (i, n) Bfs(i);
F0R (i, k) {
cin >> st >> fn >> len;
if (fastest_route[st - 1][fn - 1][len & 1] != 0
&& fastest_route[st - 1][fn - 1][len & 1] <= len) {
cout << "TAK\n";
}
else cout << "NIE\n";
}
}
Compilation message
mor.cpp: In function 'void Bfs(int)':
mor.cpp:3:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define FOR(i,x,n) for(int i=x; i<n; i++)
| ^
mor.cpp:4:18: note: in expansion of macro 'FOR'
4 | #define F0R(i,n) FOR(i,0,n)
| ^~~
mor.cpp:50:3: note: in expansion of macro 'F0R'
50 | F0R (i, adj[place].size()) {
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
299 ms |
5124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
299 ms |
4972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
2668 KB |
Output is correct |
2 |
Correct |
3 ms |
1388 KB |
Output is correct |
3 |
Correct |
23 ms |
3308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
4332 KB |
Output is correct |
2 |
Correct |
13 ms |
6124 KB |
Output is correct |
3 |
Correct |
66 ms |
6252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
169 ms |
15468 KB |
Output is correct |
2 |
Correct |
15 ms |
5740 KB |
Output is correct |
3 |
Correct |
385 ms |
23816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
805 ms |
28468 KB |
Output is correct |
2 |
Correct |
35 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1867 ms |
83180 KB |
Output is correct |
2 |
Correct |
120 ms |
24684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1936 ms |
102708 KB |
Output is correct |
2 |
Correct |
278 ms |
97388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2133 ms |
102616 KB |
Output is correct |
2 |
Correct |
522 ms |
93964 KB |
Output is correct |