Submission #709525

#TimeUsernameProblemLanguageResultExecution timeMemory
709525TAhmed33Tales of seafaring (POI13_mor)C++98
0 / 100
60 ms131072 KiB
#include <bits/stdc++.h> using namespace std; int n, m, k; vector <int> adj[5001]; int dist[5001][5001][2]; void bfs (int x) { queue <pair <int, int>> cur; cur.push({x, 0}); int cnt = 0; while (!cur.empty()) { int u = cur.size(); while (u--) { auto k = cur.front(); cur.pop(); if (k.second == 0) { dist[x][k.first][0] = cnt; for (auto j : adj[k.first]) { if (dist[x][j][1] != -1) continue; cur.push({j, 1}); } } else { dist[x][k.first][1] = cnt; for (auto j : adj[k.first]) { if (dist[x][j][0] != -1) continue; cur.push({j, 0}); } } } cnt++; } } int main () { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; memset(dist, -1, sizeof(dist)); while (m--) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; i++) { bfs(i); } while (k--) { int a, b, c; cin >> a >> b >> c; if (dist[b][c][a&1] != -1 && dist[b][c][a&1] <= a) { cout << "TAK\n"; } else { cout << "NIE\n"; } } }
#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...