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 FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define FILES {freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}
#define ll long long
#define ull unsigned long long
#define pqueue priority_queue
#define pb push_back
#define fi first
#define se second
#define ld long double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
using namespace std;
// order_of_key -> # less than k
// find_by_order -> k-th element
// pq max element
const double eps = 0.00000001;
const int NMAX = 5050;
const ll inf = LLONG_MAX/3;
const ll modi = 998244353;
vector<int>al[NMAX];
int visited[NMAX];
ll res = 0;
void dfs(int node) {
if ( visited[node]) return;
visited[node] = 1;
for (auto u : al[node]) {
if ( !visited[u]) {
dfs(u);
visited[node]+= visited[u];
}
}
res += visited[node];
}
void solve() {
int n;
cin >> n;
for (int i = 1 ; i <= n ; i++ ) {
int k;
cin >> k;
for (int j = 0 ; j < k ; j++ ) {
int a;
cin >> a;
al[a].pb(i);
}
}
ll ans = LLONG_MAX;
for (int i = 1 ; i <= n ; i++ ) {
memset(visited,0,sizeof(visited));
res = 0;
dfs(i);
ans = min(ans,res);
}
cout << ans << endl;
}
int main () {
FAST
int t=1;
/*
cin >> t;
//*/
int i = 1;
while(t--) {
//cout << "Case #" << i++ << ": " ;
solve();
}
}
Compilation message (stderr)
bosses.cpp: In function 'int main()':
bosses.cpp:73:9: warning: unused variable 'i' [-Wunused-variable]
73 | int i = 1;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |