This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
* author : Apiram
* created: 27.06.2023 03:25:28
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
vector<set<int>>adj(n);
vector<vector<int>>rev_adj(n);
for (int i = 0;i<n;++i){
int k;cin>>k;
for (int j = 0;j<k;++j){
int x;cin>>x;
--x;
adj[x].insert(i);
rev_adj[i].push_back(x);
}
}
int pos = 1e9;
for (int i = 0;i<n;++i){
queue<int>q;
vector<set<int>>bdj = adj;
int curv = 1;
int ans = 0;
vector<int>visited(n,false);
vector<int>depth(n,0);
visited[i] = true;
vector<vector<int>>nx(n);
function<pair<int,int>(int)>dfs = [&](int u){
pair<int,int> v = {1,0};
for (auto x:nx[u]){
auto vv = dfs(x);
v.first+=vv.first;
v.second+=vv.second;
}
v.second+=v.first;
return v;
};
q.push(i);
vector<int>cost(n,1);
while(!q.empty()){
auto u = q.front();
q.pop();
for (auto x:bdj[u]){
if (!visited[x]){
visited[x] = true;
depth[x] = depth[u] + 1;
nx[u].push_back(x);
q.push(x);
curv++;
for (auto y:rev_adj[x]){
bdj[y].erase(x);
}
}
}
}
if (curv == n){
//cout<<'\n';
pos = min(pos,dfs(i).second);
}
}
cout<<pos<<'\n';
return 0;
}
Compilation message (stderr)
bosses.cpp: In function 'int main()':
bosses.cpp:29:7: warning: unused variable 'ans' [-Wunused-variable]
29 | int ans = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |