Submission #515901

#TimeUsernameProblemLanguageResultExecution timeMemory
515901ac2huTales of seafaring (POI13_mor)C++14
100 / 100
1635 ms55660 KiB
#include <bits/stdc++.h> using namespace std; void setIO(string name) { #ifdef DEBUG #else ios_base::sync_with_stdio(0); cin.tie(0); freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); #endif } signed main(){ iostream::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); int n,m,k;cin >> n >> m >> k; vector<int> adj[n]; for(int i = 0;i<m;i++){ int a,b;cin >> a >> b; a--;b--; adj[a].push_back(b); adj[b].push_back(a); } string ans[k]; struct queries{ int b,d,i; }; vector<queries> qq[n]; for(int i = 0;i<k;i++){ int a,b,d;cin >> a >> b >> d; a--;b--; qq[a].push_back({b,d,i}); } for(int i = 0;i<n;i++){ int dist[n][2]; for(int j = 0;j<n;j++) dist[j][0] = dist[j][1] = 1e9 + 10; queue<pair<int,int>> q; dist[i][0] = 0; q.push({i,0}); while(!q.empty()){ pair<int,int> x = q.front(); q.pop(); for(auto e : adj[x.first]){ if(dist[e][(x.second + 1)%2] > dist[x.first][x.second] + 1){ dist[e][(x.second + 1)%2] = dist[x.first][x.second] + 1; q.push({e,(x.second + 1)%2}); } } } for(auto e : qq[i]){ // if(e.i == 3){ // cout << i << " " << e.b << " " << e.d << "\n"; // for(int i = 0;i<n;i++) // cout << dist[i][0] << " " << dist[i][1] << "\n"; // } int b = e.b,d = e.d; if(dist[b][d%2] > d || adj[b].size() == 0) ans[e.i] = "NIE"; else ans[e.i] = "TAK"; } } for(int i = 0;i<k;i++) cout << ans[i] << "\n"; }

Compilation message (stderr)

mor.cpp: In function 'void setIO(std::string)':
mor.cpp:7:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mor.cpp:8:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...