Submission #695085

#TimeUsernameProblemLanguageResultExecution timeMemory
695085NeroZeinBosses (BOI16_bosses)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5001; vector<int> g[N]; long long tmp; bitset<N> vis; inline int Dfs(int v, int dep = 1) { // cout << v << '\n'; int ret = 1; vis[v] = 1; for (int u : g[v]) { if (!vis[u]) { ret += Dfs(u, dep + 1); } } tmp += dep; return ret; } signed main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { int k; cin >> k; for (int j = 0; j < k; ++j) { int x; cin >> x; g[x].push_back(i); } } long long ans = LLONG_MAX / 3; for (int i = 1; i <= n; ++i) { vis.reset(); tmp = 0; if ( Dfs(i) == n) { ans = min(ans, tmp); } // cout << '\n'; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...