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 <bits/stdc++.h>
using namespace std;
#define A first
#define B second
#define MP make_pair
#define ms(a, x) memset(a, x, sizeof(a))
#define boost() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pld;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const int mxN=5e3+5;
vector <vector<int>> adj(mxN);
int dp[mxN][mxN][2];
void bfs(int node){
queue <int> q;
q.push(node);
dp[node][node][0]=0;
while(!q.empty()){
int u = q.front();
q.pop();
for(auto x:adj[u]){
if(dp[node][u][0]+1 < dp[node][x][1]){
dp[node][x][1] = dp[node][u][0]+1;
q.push(x);
}
}
for(auto x:adj[u]){
if(dp[node][u][1]+1 < dp[node][x][0]){
dp[node][x][0] = dp[node][u][1]+1;
q.push(x);
}
}
}
}
int main(){
ms(dp, INF);
int n, m, k;
cin >> n >> m >> k;
for(int i=0; i<m; i++){
int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
for(int i=1; i<=n; i++){
bfs(i);
}
while(k--){
int x, y, d;
cin >> x >> y >> d;
cout << (dp[x][y][(d%2)] <= d ? "TAK":"NIE") << '\n';
}
}
# | 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... |