Submission #767615

#TimeUsernameProblemLanguageResultExecution timeMemory
7676151neBosses (BOI16_bosses)C++14
67 / 100
1576 ms948 KiB
/* * 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<vector<int>>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].push_back(i); } } int pos = 1e9; function<pair<int,int>(int,vector<vector<int>>&)>dfs = [&](int u,vector<vector<int>>&nx){ pair<int,int> v = {1,0}; for (auto x:nx[u]){ auto vv = dfs(x,nx); v.first+=vv.first; v.second+=vv.second; } v.second+=v.first; return v; }; for (int i = 0;i<n;++i){ queue<int>q; int curv = 1; vector<int>visited(n,false); visited[i] = true; vector<vector<int>>nx(n); q.push(i); while(!q.empty()){ auto u = q.front(); q.pop(); for (auto x:adj[u]){ if (!visited[x]){ visited[x] = true; nx[u].push_back(x); q.push(x); curv++; } } } if (curv == n){ pos = min(pos,dfs(i,nx).second); } } cout<<pos<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...