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;
#define int long long
const int N = 5000;
vector<int> adj[N];
bool used[N];
int sal[N];
int n, c;
int calc(int v) {
vector<int> q;
for (int i : adj[v]) {
if (!used[i])
q.push_back(i), used[i] = true, c++;
}
int sum = 1;
for (int i : q)
sum += calc(i);
return sal[v] = sum;
}
int solveTestCase(int test) {
cin >> n;
for (int i = 0; i < n; i++) {
int k, v;
cin >> k;
while (k--) {
cin >> v;
adj[v - 1].push_back(i);
}
}
int ans = 1e18;
for (int i = 0; i < n; i++) {
fill(used, used + N, false);
c = 1;
used[i] = true;
calc(i);
int val = 0;
for (int j = 0; j < n; j++)
val += sal[j];
if (c == n)
ans = min(ans, val);
}
cout << ans;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int test = 1;
//cin >> test;
for (int i = 1; i <= test; i++)
solveTestCase(i);
}
Compilation message (stderr)
bosses.cpp: In function 'long long int solveTestCase(long long int)':
bosses.cpp:51:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |