This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |