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;
#pragma GCC optimize ("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
const int N = 5e3 + 5;
vector< vector<int> > g (N);
int p [N];
bitset<N> vis;
int subtree [N];
int dfs (int node) {
subtree[node] = 1;
int res = 0;
for (auto to : g[node]) {
if (p[to] == node) {
res += dfs (to);
subtree[node] += subtree[to];
}
}
return res + subtree[node];
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int k;
cin >> k;
for (int j = 0; j < k; j++) {
int st;
cin >> st;
--st;
g[st].emplace_back(i);
}
}
queue<int> q;
int mn = 1e9;
for (int i = 0; i < n; i++) {
vis.reset ();
int visited = 0;
vis[i] = 1;
p[i] = -1;
q.push(i);
while (!q.empty()) {
int node = q.front();
++visited;
q.pop();
for (auto to : g[node]) {
if (!vis[to]) {
vis[to] = 1;
p[to] = node;
q.push(to);
}
}
}
if (visited != n) continue;
mn = min (mn, dfs (i));
}
cout << mn << '\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... |