# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
790729 | christinelynn | Bosses (BOI16_bosses) | C++17 | 5 ms | 9696 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 pb push_back
#define int long long
#define INF 1e18
#define endl '\n'
using namespace std;
int n , k , ans = 1e18 , ttl = 0;
vector < int > adj[200005];
vector < int > tree[200005];
bool vis[200005];
int dfs(int cur){
int tt = 1;
for(int u : tree[cur]){
tt += dfs(u);
}
ttl += tt;
return tt;
}
void bfs(int s){
queue < int > q;
vis[s] = true;
q.push(s);
while(!q.empty()){
int u = q.front(); q.pop();
for(int i : adj[u]){
if(!vis[i]){
vis[i] = true;
q.push(i);
tree[u].pb(i);
}
}
}
ttl = 0;
int tmp = dfs(s);
//cout << s << " " << ttl << endl;
ans = min(ans , ttl);
}
signed main(){
cin >> n;
for(int i = 1 ; i <= n ; i++){
cin >> k;
for(int j = 1 ; j <= k ; j++){
int tmp; cin >> tmp;
adj[tmp].pb(i);
}
}
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= n ; j++){
vis[j] = false;
tree[j].clear();
}
bfs(i);
}
cout << ans << endl;
}
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... |