Submission #1013852

#TimeUsernameProblemLanguageResultExecution timeMemory
1013852vjudge1Tales of seafaring (POI13_mor)C++17
100 / 100
1342 ms116136 KiB
#include <bits/stdc++.h> using namespace std; #define endl "\n" short dis[5001][5001][2]; vector <int> v[5001]; queue <pair<int,int>> qu; int n,m,k,w,a,b,d; void bfs(int x){ for(int i=1;i<=n;i++) dis[x][i][0]=dis[x][i][1]=1e4+1; dis[x][x][0]=0; qu.push({0,x}); while(qu.size()!=0){ auto[mydis,i]=qu.front(); qu.pop(); if(mydis>dis[x][i][mydis%2]) continue; for(int j:v[i]){ w=mydis+1; if(dis[x][j][w%2]>w){ 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); } //bfs(); 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(dis[a][b][d%2]<=d&&dis[a][b][d%2]!=1e4+1) cout<<"TAK"<<endl; else cout<<"NIE"<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...