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>
using namespace std;
typedef long long ll;
int g, n, m;
vector<vector<vector<int>>> table;
vector<ll> dp;
inline ll f(int a, bitset<100> vis) {
if(dp[a] != -1) return dp[a];
vis[a] = true;
ll ret = INT64_MAX;
for(auto &x : table[a]) {
ll cur = 0;
for(auto &y : x) {
if(vis[y]) {
cur = -2;
break;
}
cur += f(y, vis);
}
if(cur == -2) {
continue;
}
ret = min(ret, cur);
}
dp[a] = ret;
return dp[a];
}
int main() {
cin >> g >> n >> m;
table.resize(g);
for(int i = 0; i < n; i ++) {
int a, k;
cin >> a >> k;
table[a].push_back(vector<int>(k));
for(int j = 0; j < k; j ++) {
cin >> table[a].back()[j];
}
}
for(int i = 0; i < m; i ++) {
int k;
cin >> k;
for(int j = 0; j < k; j ++) {int tmp; cin >> tmp;}
}
dp.assign(g, -1);
dp[0] = dp[1] = 1;
for(int i = 0; i < g; i ++) {
cout << f(i, bitset<100>(0)) << '\n';
}
}
# | 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... |