Submission #980141

#TimeUsernameProblemLanguageResultExecution timeMemory
980141nhuang685Tales of seafaring (POI13_mor)C++17
30 / 100
1167 ms117832 KiB
#include <bits/stdc++.h> int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int n, m, k; std::cin >> n >> m >> k; std::vector<std::vector<int>> adj(n); for (int i = 0; i < m; ++i) { int a, b; std::cin >> a >> b; --a; --b; adj[a].push_back(b); adj[b].push_back(a); } std::vector<std::vector<std::array<short, 2>>> dist(n, std::vector<std::array<short, 2>>(n)); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { dist[i][j][0] = dist[i][j][1] = 10000; } } auto sp = [&](int st) { // std::vector<std::array<int, 2>> dist(n, {(int)2e9, (int)2e9}); dist[st][st][0] = 0; std::queue<std::pair<int, bool>> q; q.emplace(st, 0); while (!q.empty()) { auto [node, par] = q.front(); q.pop(); for (int i : adj[node]) { if (dist[st][i][!par] > dist[st][node][par] + 1) { dist[st][i][!par] = dist[st][node][par] + 1; q.push({i, !par}); } } } }; for (int i = 0; i < n; ++i) { sp(i); } while (k--) { int s, t, d; std::cin >> s >> t >> d; --s; --t; if (d >= dist[s][t][d % 2] && (int)adj[s].size() > 0) { std::cout << "TAK\n"; } else { std::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...