Submission #717846

#TimeUsernameProblemLanguageResultExecution timeMemory
717846nninBosses (BOI16_bosses)C++14
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<int,int> #define f first #define s second using namespace std; vector<int> adj[5002]; int n; pii dfs(int curr, vector<bool> &vis) { vector<int> v; for(int next:adj[curr]) { if(!vis[next]) { vis[next] = 1; v.push_back(next); } } pii ans = {0, 1}; for(int next:v) { pii tmp = dfs(next, vis); ans.f += tmp.f; ans.s += tmp.s; } ans.f += ans.s; return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; for(int i=1;i<=n;i++) { int k, v; cin>>k; while(k--) { cin>>v; adj[v].push_back(i); } } int ans = INT_MAX; for(int root=1;root<=n;root++) { vector<bool> vis(n+1, 0); vis[root] = 1; ans = min(ans, dfs(root, vis).f); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...