Submission #813232

#TimeUsernameProblemLanguageResultExecution timeMemory
813232vjudge1Bosses (BOI16_bosses)C++17
0 / 100
1 ms572 KiB
#include <bits/stdc++.h> using namespace std; const int NM = 5000; const int INF = 1e9+7; vector<int> g[NM+5]; bool vis[NM+5]; vector<int> g2[NM+5]; int val[NM+5]; void bfs(int u){ queue<int> q; q.push(u); vis[u] = 1; while(!q.empty()){ u = q.front(); q.pop(); g2[u].clear(); for (int& v : g[u]){ if (vis[v]) continue; g2[u].push_back(v); vis[v] = 1; q.push(v); } } } void dfs(int u){ val[u] = 1; for (int& v : g2[u]){ dfs(v); val[u] = max(val[u], val[v] + 1); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++){ int k; cin >> k; g[i].resize(k); for (int& j : g[i]) cin >> j; } int res = INF; for (int i = 1; i <= n; i++){ memset(vis, 0, sizeof vis); bfs(i); bool ok = true; for (int j = 1; j <= n; j++){ if (vis[j] == false){ ok = false; break; } } if (ok){ dfs(i); int sum = 0; for (int j = 1; j <= n;j ++){ sum += val[i]; } res = min(res, sum); } } cout << res << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...