# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
813370 | SteGG | Bosses (BOI16_bosses) | C++17 | 1118 ms | 980 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 int long long
using namespace std;
void open(){
if(fopen("input.inp", "r")){
freopen("input.inp", "r", stdin);
// freopen("output.out", "w", stdout);
}
}
const int inf = 3e18;
const int maxn = 5005;
int n;
vector<int> candidate[maxn];
vector<int> tr[maxn];
bool check[maxn];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
open();
cin >> n;
for(int i = 1; i <= n; i++){
int k;
cin >> k;
for(int j = 1; j <= k; j++){
int a;
cin >> a;
candidate[a].push_back(i);
}
}
int result;
int last_result = inf;
auto dfs = [&](auto &&dfs, int u) -> int {
int sz = 1;
for(int v : tr[u]){
sz += dfs(dfs, v);
}
result += sz;
return sz;
};
for(int root = 1; root <= n; root++){
memset(check, false, sizeof(check));
for(int i = 0; i <= n; i++){
tr[i].clear();
}
queue<pair<int, int>> q;
q.push({root, 0});
int cnt = 0;
while(!q.empty()){
int u = q.front().first;
int p = q.front().second;
q.pop();
if(check[u]) continue;
cnt++;
check[u] = true;
tr[p].push_back(u);
for(int v : candidate[u]){
if(check[v]) continue;
q.push({v, u});
}
}
if(cnt < n) continue;
result = 0;
dfs(dfs, root);
last_result = min(result, last_result);
}
cout << last_result << endl;
return 0;
}
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... |