Submission #723581

#TimeUsernameProblemLanguageResultExecution timeMemory
723581rshohruhBosses (BOI16_bosses)C++14
0 / 100
1 ms304 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<int> > g; vector<int> p; int n; const int inf = 1e9; int dfs(int u){ p[u] = 1; for(int v: g[u]){ if(p[v] == -1){ p[v] = 1; dfs(v); p[u] += p[v]; } } int ans = 0; for(int i = 1; i <= n; ++i){ if(p[i] == -1) return inf; ans += p[i]; } return ans; } int res(int u){ p.assign(n+1, -1); return dfs(u); } int main(){ cin >> n; g.resize(n+1); for(int i = 1, k; i <= n; ++i){ cin >> k; g[i].resize(k); for(int j = 0; j < k; ++j) cin >> g[i][j]; } int ans = inf; for(int u = 1; u <= n; ++u) ans = min(ans, res(u)); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...