# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
813330 | vjudge1 | Bosses (BOI16_bosses) | C++17 | 1 ms | 724 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 = 1e9 + 7;
const int maxn = 1e4 + 5;
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 root = 0;
int max_adj = 0;
for(int i = 1; i <= n; i++){
if(root == 0 || max_adj < candidate[i].size()){
root = i;
max_adj = candidate[i].size();
}
}
queue<pair<int, int>> q;
q.push({root, 0});
while(!q.empty()){
int u = q.front().first;
int p = q.front().second;
q.pop();
if(check[u]) continue;
check[u] = true;
tr[p].push_back(u);
for(int v : candidate[u]){
if(check[v]) continue;
q.push({v, u});
}
}
int result = 0;
auto dfs = [&](auto &&dfs, int u) -> int {
int sz = 1;
for(int v : tr[u]){
sz += dfs(dfs, v);
}
result += sz;
return sz;
};
dfs(dfs, root);
cout << 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... |