/*
Code by @marlov
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
#define maxN 5005
const short INF = 31111;
int N,M,K;
vector<int> adj[maxN];
//from u to v min even and min odd
short dist[maxN][maxN][2];
void bfs(int p){
queue< pair<int,int> > q;
dist[p][p][0]=0;
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<adj[cn].size();i++){
int nn=adj[cn][i];
if(dist[p][nn][(cd+1)%2]>cd+1){
dist[p][nn][(cd+1)%2]=cd+1;
q.push(make_pair(nn,cd+1));
}
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
for(int i=0;i<maxN;i++){
for(int j=0;j<maxN;j++){
if(i!=j){
dist[i][j][0]=INF;
}
dist[i][j][1]=INF;
}
}
cin>>N>>M>>K;
int u,v;
for(int i=0;i<M;i++){
cin>>u>>v;
u--;
v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=0;i<N;i++){
bfs(i);
}
int a,b,d;
for(int i=0;i<K;i++){
cin>>a>>b>>d;
a--;
b--;
if( (dist[a][b][d%2]!=INF&&dist[a][b][d%2]<=d) && !(d > 0 && adj[a].size() == 0) ){
cout<<"TAK"<<'\n';
}else{
cout<<"NIE"<<"\n";
}
}
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1,n=0?)
* do smth instead of nothing and stay organized
*/
Compilation message
mor.cpp: In function 'void bfs(int)':
mor.cpp:25:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i=0;i<adj[cn].size();i++){
| ~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
98424 KB |
Output is correct |
2 |
Correct |
77 ms |
98424 KB |
Output is correct |
3 |
Correct |
77 ms |
98424 KB |
Output is correct |
4 |
Correct |
395 ms |
118008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
98424 KB |
Output is correct |
2 |
Correct |
70 ms |
98424 KB |
Output is correct |
3 |
Correct |
70 ms |
98424 KB |
Output is correct |
4 |
Correct |
402 ms |
117908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
98520 KB |
Output is correct |
2 |
Correct |
70 ms |
98424 KB |
Output is correct |
3 |
Correct |
69 ms |
98680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
98552 KB |
Output is correct |
2 |
Correct |
70 ms |
98552 KB |
Output is correct |
3 |
Correct |
89 ms |
98500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
105 ms |
98752 KB |
Output is correct |
2 |
Correct |
79 ms |
98680 KB |
Output is correct |
3 |
Correct |
135 ms |
98840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
230 ms |
98936 KB |
Output is correct |
2 |
Correct |
79 ms |
98680 KB |
Output is correct |
3 |
Correct |
430 ms |
98812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
932 ms |
116436 KB |
Output is correct |
2 |
Correct |
90 ms |
98680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1945 ms |
116216 KB |
Output is correct |
2 |
Correct |
172 ms |
101752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2070 ms |
117772 KB |
Output is correct |
2 |
Correct |
333 ms |
103800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2267 ms |
118008 KB |
Output is correct |
2 |
Correct |
594 ms |
112888 KB |
Output is correct |