Submission #337870

#TimeUsernameProblemLanguageResultExecution timeMemory
337870theshadow_04Bosses (BOI16_bosses)C++14
22 / 100
34 ms2668 KiB
#include <bits/stdc++.h> #define Task "BOSSES" #define pb push_back #define F first #define S second using namespace std; const int maxn = 100005; int n, cnt = 0; vector<int> ke[maxn]; int f[maxn], In[maxn], ans = 2e9; pair<int, int> ed[maxn]; void DFS(int u) { int sum = 0; for(auto v : ke[u]) { if(!f[v]) { DFS(v); sum += f[v]; } } f[u] = sum + 1; } void Solve(int mask) { for(int i = 1; i <= n; ++ i) f[i] = 0, ke[i].clear(), In[i] = 0; for(int i = 1; i <= cnt; ++ i) { if((mask >> (i - 1)) & 1) ke[ed[i].F].pb(ed[i].S), In[ed[i].S] = 1; } int root = 0; for(int i = 1; i <= n; ++ i) { if(!In[i]) { if(root) return; root = i; } } DFS(root); int total = 0; for(int i = 1; i <= n; ++ i) { if(!f[i]) return; total += f[i]; } ans = min(ans, total); } int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); if(fopen(Task".inp", "r")) { freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); } cin >> n; for(int i = 1; i <= n; ++ i) { int k; cin >> k; while(k --) { int x; cin >> x; ed[++ cnt] = {x, i}; } } for(int mask = 1; mask < (1 << cnt); ++ mask) { if(__builtin_popcount(mask) != n - 1) continue; Solve(mask); } cout << ans; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   52 |         freopen(Task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   53 |         freopen(Task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...