Submission #910950

#TimeUsernameProblemLanguageResultExecution timeMemory
910950oblantisBosses (BOI16_bosses)C++17
100 / 100
387 ms772 KiB
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #pragma GCC optimize("O3,unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define all(v) v.begin(), v.end() #define pb push_back #define ss second #define ff first #define vt vector using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int, int> pii; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int inf = 1e9; const int mod = 1e9+7; const int maxn = 1e5 + 1; void solve() { int n; cin >> n; bool was[n]; vt<int> v[n]; for(int i = 0; i < n; i++){ int k; cin >> k; for(int j = 0, t; j < k; j++) { cin >> t; t--; v[t].pb(i); } } int sum = n * n; for(int i = 0; i < n; i++){ memset(was, 0, sizeof was); queue<pii> q; q.push({i, 1}); was[i] = 1; int ans = 0, cnt = 0; while(!q.empty()){ pii nw = q.front(); q.pop(); ans += nw.ss; cnt++; for(auto j : v[nw.ff]){ if(!was[j])was[j] = 1, q.push({j, nw.ss + 1}); } } if(cnt == n)sum = min(sum , ans); } cout << sum; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int times = 1; //cin >> times; for(int i = 1; i <= times; i++) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...