# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1013890 | vjudge1 | Tales of seafaring (POI13_mor) | C++17 | 431 ms | 131072 KiB |
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;
using ll = long long;
vector<bool> vis(5006);
vector<ll> v[5006];
ll dis[5006][5006],win[5006];
bool b[5006][5006];
ll n,m;
void bfs(ll i){
queue<pair<ll,ll>> q;
q.push({i,0});
bool vi[5006]={};
dis[i][i]=0;
b[i][i]=1;
vi[i]=1;
while(!q.empty()){
pair<ll,ll> x=q.front();
q.pop();
for(int j=0;j<v[x.first].size();j++){
if(!vi[v[x.first][j]]){
vi[v[x.first][j]]=1;
dis[i][v[x.first][j]]=x.second+1;
b[i][v[x.first][j]]=1;
q.push({v[x.first][j],x.second+1});
}
else{
if(dis[i][v[x.first][j]]%2!=(dis[i][x.first]+1)%2){
win[v[x.first][j]]=(dis[i][x.first]+1)-dis[i][v[x.first][j]];
}
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll q;
cin>>n>>m>>q;
for(int i=0;i<m;i++){
ll x,y;
cin>>x>>y;x--;y--;
v[x].push_back(y);
v[y].push_back(x);
}
for(int i=0;i<n;i++)bfs(i);
for(int i=0;i<n;i++){
if(win[i]>0){
for(int j=0;j<n;j++){
if(b[i][j]){
if(win[j]==0||win[j]>win[i])win[j]=win[i];
}
}
}
}
while(q--){
ll x,y,d;
cin>>x>>y>>d;
x--;y--;
if(b[x][y]){
if((win[x]!=0)&&win[x]+dis[x][y]<=d){
cout<<"TAK\n";
}
else if(dis[x][y]<=d&&dis[x][y]%2==d%2){
cout<<"TAK\n";
}
else{
cout<<"NIE\n";
}
}
else{
cout<<"NIE\n";
}
}
}
Compilation message (stderr)
# | 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... |