# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
337870 | theshadow_04 | Bosses (BOI16_bosses) | C++14 | 34 ms | 2668 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |