제출 #1235955

#제출 시각아이디문제언어결과실행 시간메모리
1235955sebokxBosses (BOI16_bosses)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define st first
#define nd second 
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define len(x) (int)(x).size()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
template <typename T, typename H>
ostream& operator<<(ostream& os, pair<T, H> p){
	return os << "(" << p.st << ", " << p.nd << ")";
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v){
	os << "{";
	for(int i = 0; i < v.size(); i++){
		if(i != 0) os << ", ";
		os << v[i];
	}
	os << "}";
	return os;
}
#ifdef DEBUG
#define fastio()
#define debug(x...) cerr << "[" << #x << "]: ", [](auto... $) {((cerr << $ << ", "), ...); }(x), cerr << '\n'
#else
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x...)
#endif
#define int ll

const int MAXN = 5'007;
vector<int> g[MAXN];
bool vis[MAXN];
int n;

int bfs(int v){
	queue<pair<int, int>> que;
	que.push(mp(v, 1));
	vis[v] = true;
	int ans = 0;
	cout << v << ' '; 
	while(!que.empty()){
		auto [w, d] = que.front();
		que.pop();

		ans += d;
		for(auto u : g[w]){
			if(vis[u])
				continue;
			vis[u] = true;
			que.push(mp(u, d+1));
		}
	}

	for(int i = 0; i < n; i++){
		if(vis[i] == false)
			return INT_MAX;
	}
	return ans;
}

void solve(){
	cin >> n;

	for(int i = 0; i < n; i++){
		int siz;
		cin >> siz;
		for(int j = 0; j < siz; j++){
			int a;
			cin >> a;
			g[a-1].pb(i);
		}
	}

	int ans = INT_MAX;
	for(int i = 0; i < n; i++){
		fill(vis, vis+n, false);
		ans = min(ans, bfs(i));
	}

	cout << ans << '\n';
}

int32_t main(){
    fastio();

    int tt = 1;
    // cin >> tt;
    while(tt--) solve();

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...