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 endl "\n"
map <array<int,3>,int> dis;
vector <int> v[5001];
queue <pair<int,int>> qu;
int n,m,k,w,a,b,d;
void bfs(int x){
dis[{x,x,0}]=-1;
qu.push({0,x});
while(qu.size()!=0){
auto[mydis,i]=qu.front();
qu.pop();
for(int j:v[i]){
w=mydis+1;
if(dis[{x,j,w%2}]>w||dis[{x,j,w%2}]==0){
dis[{x,j,w%2}]=w;
qu.push({w,j});
}
}
}
return;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m>>k;
for(int i=0;i<m;i++){
cin>>a>>b;
v[a].push_back(b);
v[b].push_back(a);
}
for(int i=1;i<=n;i++) bfs(i);
while(k--){
cin>>a>>b>>d;
if(a==b&&d!=0&&v[a].size()==0) cout<<"NIE"<<endl;
else if(a==b&&d==0) cout<<"TAK"<<endl;
else if(dis[{a,b,d%2}]<=d&&dis[{a,b,d%2}]!=0) cout<<"TAK"<<endl;
else cout<<"NIE"<<endl;
}
return 0;
}
Compilation message (stderr)
mor.cpp: In function 'void bfs(int)':
mor.cpp:12:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
12 | auto[mydis,i]=qu.front();
| ^
# | 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... |