제출 #980147

#제출 시각아이디문제언어결과실행 시간메모리
980147nhuang685새로운 문제 (POI13_mor)C++17
100 / 100
1154 ms102712 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; d = std::min(d, 9998 + d % 2); 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...