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 pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
const int MAXN = 5e3+10;
vector<int> ac[MAXN], b[MAXN];
vector<int> f[MAXN];
long long cr = 0;
long long dfs(int x){
if (f[x].empty()){
cr++;
return 1;
}
long long tt = 0;
for (auto &i:f[x]){
tt+=dfs(i);
}
cr+=tt+1;
return tt+1;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n;
for (int i=1;i<=n;i++){
cin >> k;
b[i].resize(k);
for (auto &x:b[i]){
cin >> x;
ac[x].push_back(i);
}
}
long long ans = 1e18+1;
for (int b=1;b<=n;b++){
vector<bool> v(n+1, 0);
for (int i=1;i<=n;i++) f[i].clear();
queue<int> q;
v[b] = 1;
q.push(b);
int tt = 0;
while (!q.empty()){
int u = q.front();
tt++;
q.pop();
for (auto &i:ac[u]) if (!v[i]){
v[i]=1;
f[u].push_back(i);
q.push(i);
}
}
if (tt!=n) continue;
cr = 0;
dfs(b);
ans = min(ans, cr);
}
cout << ans << '\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... |