# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338068 | theshadow_04 | Bosses (BOI16_bosses) | C++14 | 1536 ms | 3180 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.
// V T An
#include <bits/stdc++.h>
#define Task "BOSSES"
#define pb push_back
#define F first
#define S second
using namespace std;
const int maxn = 50005;
int n;
vector<int> a[maxn], ke[maxn];
int dd[maxn];
int ans = 2e9, f[maxn];
int Q[maxn], bot = 1, top = 0;
void BFS(int s) {
bot = 1, top = 0;
Q[++ top] = s;
dd[s] = 1;
while(bot <= top) {
int u = Q[bot ++];
for(auto v : a[u]) {
if(!dd[v]) {
dd[v] = 1;
ke[u].pb(v);
Q[++ top] = v;
}
}
}
}
void DFS(int u) {
f[u] = 1;
for(auto v : ke[u]) {
if(!f[v]) {
DFS(v);
f[u] += f[v];
}
}
}
void Solve(int u) {
for(int i = 1; i <= n; ++ i) ke[i].clear(), f[i] = dd[i] = 0;
BFS(u);
DFS(u);
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;
a[x].pb(i);
}
}
for(int i = 1; i <= n; ++ i) {
Solve(i);
}
cout << ans;
}
// CHY-AKAV
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... |