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>
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);
#define what(x) cerr << #x << " is " << x << '\n';
#define kill(x) {cout << x << '\n'; return 0;}
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define pb push_back
#define ll long long
#define F first
#define S second
const ll inf = 1e18, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 450, P = 6065621;
using namespace std;
#define int ll
const ll N = 5e3 + 10, LG = 20;
vector<int> adj[N];
vector<int> G[N];
bitset<N> mark;
int dp[N];
void dfs (int v) {
dp[v] = 1;
for (auto u: G[v]) {
dfs(u);
dp[v] += dp[u];
}
}
int32_t main() {
fast_io;
int n, ans = inf;
cin >> n;
for (int i = 1; i <= n; i++) {
int k, x;
cin >> k;
while (k--) {
cin >> x;
adj[x].pb(i);
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
G[j].clear();
queue<int> q;
mark.reset();
q.push(i);
mark[i] = true;
while (q.size()) {
int v = q.front();
q.pop();
for (auto u: adj[v]) {
if (!mark[u]) {
q.push(u);
mark[u] = true;
G[v].pb(u);
}
}
}
dfs(i);
int sum = 0;
for (int j = 1; j <= n; j++)
sum += dp[j];
ans = min(ans, sum);
}
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... |