Submission #1150541

#TimeUsernameProblemLanguageResultExecution timeMemory
1150541zhasynBosses (BOI16_bosses)C++20
100 / 100
718 ms1016 KiB
//#include "ricehub.h"
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 5000 + 100, M = 4096 + 10, len = 21, inf = 1e18;
const ll mod = 1e9 + 7;

vector <int> q[N], lt[N];
int was[N], sm;
int dfs(int v){
	int rs = 0;
	for(auto u : lt[v]){
		rs += dfs(u);
	}
	sm = sm + rs + 1;
	return rs + 1;
}
int main(){
  	ios::sync_with_stdio(false);
  	cin.tie(NULL); 	
  	int n, ans = INT_MAX;
  	cin >> n;
  	for(int i = 1, k; i <= n; i++){
  		cin >> k;
  		for(int j = 0, x; j < k; j++){
  			cin >> x;
  			q[x].pb(i);
  		}
  	}
  	
  	for(int i = 1; i <= n; i++){
  		for(int j = 1; j <= n; j++){
  			was[j] = false;
  			lt[j].clear();
  		}
  		int cnt = 1;
  		was[i] = true;
  		queue <int> g;
  		g.push(i);
  		while((int)g.size() != 0){
  			int v = g.front();
  			g.pop();
  			for(auto u : q[v]){
  				if(was[u]) continue;
  				cnt++;
  				was[u] = true;
  				lt[v].pb(u);
  				g.push(u);
  			}
  		}
  		if(cnt == n){
  			sm = 0;
  			dfs(i);
  			ans = min(ans, sm);
  		}
  	}
  	cout << ans;
    return 0;
}
 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...