제출 #395428

#제출 시각아이디문제언어결과실행 시간메모리
395428KoDViruses (BOI20_viruses)C++17
11 / 100
1 ms424 KiB
#include <bits/stdc++.h> template <class T> using Vec = std::vector<T>; using ll = long long; int main() { int G, N, M; std::cin >> G >> N >> M; Vec<Vec<Vec<int>>> graph(G); while (N--) { int a, k; std::cin >> a >> k; Vec<int> b(k); for (auto& x: b) { std::cin >> x; } graph[a].push_back(std::move(b)); } assert(M == 0); Vec<ll> shortest(G, -1); shortest[0] = shortest[1] = 1; while (true) { bool change = false; for (int i = 2; i < G; ++i) { for (const auto& v: graph[i]) { ll sum = 0; for (const auto x: v) { if (shortest[x] == -1) { sum = -1; break; } sum += shortest[x]; } if (sum != -1 and (shortest[i] == -1 or shortest[i] > sum)) { shortest[i] = sum; change = true; } } } if (!change) { break; } } for (int i = 2; i < G; ++i) { if (shortest[i] == -1) { std::cout << "YES\n"; } else { std::cout << "NO " << shortest[i] << '\n'; } } 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...