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;
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main(){
int n,m,q;
cin>>n>>m>>q;
vector<int> adj[n];
ll odd[n][n];
ll even[n][n];
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
odd[i][j]=even[i][j]=1e9;
}
}
for (int i = 0; i < n; ++i)
{
even[i][i]=0;
}
for (int i = 0; i < m; ++i)
{
int x,y;
cin>>x>>y;
x--;y--;
adj[x].pb(y);
adj[y].pb(x);
odd[x][y]=odd[y][x]=1;
}
for (int k = 0; k < n; ++k)
{
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
odd[i][j]=min(odd[i][j],min(odd[i][k]+even[k][j],even[i][k]+odd[k][j]));
even[i][j]=min(even[i][j],min(even[i][k]+even[k][j],odd[i][k]+odd[k][j]));
odd[j][i]=min(odd[i][j],odd[j][i]);
even[j][i]=min(even[i][j],even[j][i]);
}
}
}
while(q--){
ll x,y,z;
cin>>x>>y>>z;
x--;y--;
if(z%2==0&&z>=even[x][y]) cout <<"TAK"<<endl;
else if(z%2&&z>=odd[x][y]) cout <<"TAK"<<endl;
else cout <<"NIE"<<endl;
}
}
# | 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... |