Submission #99373

#TimeUsernameProblemLanguageResultExecution timeMemory
99373ryanseeBosses (BOI16_bosses)C++14
100 / 100
704 ms760 KiB
#include "bits/stdc++.h" using namespace std; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); #define LLINF (long long) 1e18//1234567890987654321 #define INF 1234567890l #define pb push_back #define ins insert #define f first #define s second #define db 0 #define EPS (1e-7) //0.0000001 the value #define PI (acos(-1)) #define MAXN 300006 #define MAXK 26 #define MAXX 15000006 #define ll long long int #define ld long double mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng) #define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++) #define space " " #define cbr cout << "hi\n" #define mmst(x, v) memset((x), v, sizeof ((x))) #define bg(ms) (*ms.begin()) #define ed(ms) (*prev(ms.end(), 1)) #define addedge(a, b, c, v) v[(a)].pb(pi((b), (c))); v[(b)].pb(pi((a), (c))) #define ph push #define btinpct(x) __builtin_popcountll(x) #define p2(x) (1LL<<(x)) #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi; inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss ll n, dist[5006]; vector <int> v[5006]; ll bfs(ll x) { queue <ll> q; mmst(dist,-1); q.ph(x); dist[x] = 0; while(!q.empty()) { ll x = q.front(); q.pop(); for(auto i : v[x]) { if(dist[i] != -1) { assert(dist[i] <= dist[x] + 1); continue; } dist[i] = dist[x] + 1; q.ph(i); } } ll ans = 0; FOR(i,1,n+1) { if(dist[i] == -1) return LLINF; ans += dist[i]; } ans += n; return ans; } int main() { cin >> n; FOR(i,1,n+1) { ll k; cin >> k; for(ll j = 0; j < k; j++) { ll a; cin >> a; v[a].pb(i); } } ll ans = LLINF; FOR(i,1,n+1) ans = min(ans, bfs(i)); cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...