Submission #860069

#TimeUsernameProblemLanguageResultExecution timeMemory
860069kh0iBosses (BOI16_bosses)C++17
100 / 100
394 ms856 KiB
#include "bits/stdc++.h" using namespace std; #define F first #define S second #define sz(x) (int)((x).size()) using ll = long long; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll get_rand(ll l, ll r) { assert(l <= r); return uniform_int_distribution<ll> (l, r)(rng); } #ifdef LOCAL #include "debug.h" #else #define debug(...) #endif const int N = 5003; int n, ans = INT_MAX, d[N]; vector<int> g[N]; void bfs(int st){ memset(d, -1, sizeof(d)); d[st] = 1; queue<int> q; q.push(st); while(!q.empty()){ int u = q.front(); q.pop(); for(int v : g[u]){ if(d[v] == -1){ d[v] = d[u] + 1; q.push(v); } } } int tot = 0; for(int i = 1; i <= n; ++i){ if(d[i] == -1) return; tot += d[i]; } ans = min(ans, tot); } void solve(){ cin >> n; for(int i = 1; i <= n; ++i){ int k, u; cin >> k; for(int j = 1; j <= k; ++j){ cin >> u; g[u].push_back(i); } } for(int i = 1; i <= n; ++i){ bfs(i); } cout << ans; } int32_t main() { cin.tie(nullptr)->sync_with_stdio(0); int test = 1; // cin >> test; for(int i = 1; i <= test; ++i){ // cout << "Case #" << i << ": "; solve(); } cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...