This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"
vector<vector<int>> g;
vector<bool> vis;
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n; cin >> n;
g.resize(n);
vis.resize(n);
for(int i=0; i<n; ++i){
int k; cin >> k;
for(int j=0; j<k; ++j){
int x; cin >> x;
g[x-1].push_back(i);
}
}
int curr[n];
int ans = 1e18;
for(int root=0; root<n; ++root){
for(int i=0; i<n; ++i){
vis[i] = false;
curr[i] = 1;
}
vector<int> order;
order.push_back(root);
vis[root] = true;
bool ok = true;
int parent[n];
for(int i=0; i<n; ++i){
if(i==(int)order.size()){
ok = false;
break;
}
int u = order[i];
for(int v : g[u]){
if(!vis[v]){
vis[v] = true;
order.push_back(v);
parent[v] = u;
}
}
}
if(!ok) continue;
reverse(order.begin(), order.end());
for(int i=0; i+1<(int)order.size(); ++i){
curr[parent[order[i]]] += curr[order[i]];
}
ans = min(ans, accumulate(curr, curr+n, 0LL));
}
cout << ans nl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |