Submission #1111152

#TimeUsernameProblemLanguageResultExecution timeMemory
1111152Ghulam_JunaidBosses (BOI16_bosses)C++17
100 / 100
1033 ms1360 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 10; int n, par[N], sz[N], ans; vector<int> out[N], in[N], g[N]; bool seen[N]; void dfs(int v, int p = -1){ sz[v] = 1; for (int u : g[v]){ if (u == p) continue; dfs(u, v); sz[v] += sz[u]; } ans += sz[v]; } int main(){ cin >> n; for (int i = 1; i <= n; i ++){ int k, x; cin >> k; for (int j = 0; j < k; j ++){ cin >> x; out[i].push_back(x); in[x].push_back(i); } } int output = 1e9; for (int root = 1; root <= n; root ++){ ans = 0; for (int i = 1; i <= n; i ++) g[i].clear(), seen[i] = 0; queue<int> q; q.push(root); seen[root] = 1; while (!q.empty()){ int v = q.front(); q.pop(); for (int u : in[v]){ if (!seen[u]){ q.push(u); seen[u] = 1; g[u].push_back(v); g[v].push_back(u); } } } bool all = 1; for (int i = 1; i <= n; i ++) all &= seen[i]; if (all){ dfs(root); output = min(output, ans); } } cout << output << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...