Submission #873263

#TimeUsernameProblemLanguageResultExecution timeMemory
873263bobbilykingBosses (BOI16_bosses)C++17
100 / 100
379 ms864 KiB
#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include<bits/stdc++.h> #include<math.h> using namespace std; typedef int ll; typedef long double ld; typedef pair<ll, ll> pl; #define K first #define V second #define G(x) ll x; cin >> x; #define GD(x) ld x; cin >> x; #define GS(s) string s; cin >> s; #define EX(x) { cout << x << '\n'; exit(0); } #define A(a) (a).begin(), (a).end() #define F(i, l, r) for (ll i = (l); i < r; ++i) #define NN #define M 1000000007 // 998244353 vector<ll> availWhenPlaced[5010]; int main(){ // freopen("a.in", "r", stdin); // freopen("a.out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); G(n) F(i, 1, n+1) { G(k) while(k--) { G(t) availWhenPlaced[t].push_back(i); } } ll ans = n*n; F(root, 1, n+1) { vector<bool> vis(n+1); vector<ll> q{root}, nq; vis[root] = 1; ll tans = 0; for (ll dep = 1; q.size(); swap(q, nq), nq.clear(), dep++) { for (const auto &x: q) { tans += dep; for (const auto &y: availWhenPlaced[x]) if (!vis[y]) { vis[y] = 1; nq.push_back(y); } } } if (count(A(vis), true) == n) ans = min(ans, tans); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...