#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
typedef long long ll;
typedef pair<int, int> pii;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int n, m, k;
short dp[5005][5005][2];
vector<int> adj[5005];
bool vis[5005][2];
queue<pair<int,short>> q;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> k;
for(int i = 0; i < m;i ++){
int a, b;
cin >> a >> b;
a--; b--;
adj[a].pb(b);
adj[b].pb(a);
}
for(int i = 0; i < n;i ++){
for(int j = 0;j < n;j ++){
dp[i][j][0] = 5001;
dp[i][j][1] = 5001;
}
}
for(int i = 0;i < n; i++){
//launch a bfs from node i
memset(vis, false, sizeof(vis));
vis[i][0] = true;
q.push({i,0});
dp[i][i][0] = 0;
while(!q.empty()){
pair<int,short> c = q.front(); q.pop();
//if(c.s != dp[i][c.f][c.s%2])continue;
for(int u : adj[c.f]){
int pa = c.s%2;
if(!vis[u][(pa+1)%2]){
vis[c.f][c.s%2] = true;
dp[i][u][(pa+1)%2] = min(dp[i][u][(pa+1)%2],(short)(c.s+1));
q.push({u, (c.s+1)});
}
}
}
}
for(int i = 0; i < k;i ++){
int a, b, d;
cin >> a >> b >> d;
a--; b--;
bool works = false;
if(dp[a][b][d%2] <= d && dp[a][b][d%2] != 5001)works = true;
cout << (works ? "TAK":"NIE") << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
3 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
748 KB |
Output is correct |
2 |
Correct |
2 ms |
620 KB |
Output is correct |
3 |
Correct |
2 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
2796 KB |
Output is correct |
2 |
Correct |
5 ms |
1388 KB |
Output is correct |
3 |
Correct |
125 ms |
3564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
336 ms |
4588 KB |
Output is correct |
2 |
Correct |
27 ms |
6252 KB |
Output is correct |
3 |
Incorrect |
413 ms |
6380 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
221 ms |
15468 KB |
Output is correct |
2 |
Correct |
32 ms |
5868 KB |
Output is correct |
3 |
Incorrect |
1845 ms |
24556 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3030 ms |
25856 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3082 ms |
79084 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2180 ms |
102608 KB |
Output is correct |
2 |
Correct |
364 ms |
97300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2838 ms |
102764 KB |
Output is correct |
2 |
Correct |
666 ms |
93932 KB |
Output is correct |