Submission #504863

#TimeUsernameProblemLanguageResultExecution timeMemory
504863banterbryBosses (BOI16_bosses)C++17
0 / 100
1 ms332 KiB
#undef _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define int long long #define pb push_back #define fi first #define si second #define ar array #define dd double typedef pair<int,int> pi; typedef tuple<int,int,int> ti; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);} #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) int N, dist[1010], vis[1010], ans = 1e14, dp[1010]; vector<int> adj[1010], child[1010], order; queue<int> q; void dfs(int x) { for (auto i: adj[x]) { if (vis[i]) continue; vis[i] = 1; dfs(i); } order.pb(x); } signed main() { fast; cin >> N; for (int i = 1; i <= N; ++i) { int k; cin >> k; for (int j = 0; j < k; ++j) { int x; cin >> x; adj[x].pb(i); } } for (int person = 1; person <= N; ++person) { for (int i = 1; i <= N; ++i) child[i].clear(); order.clear(); memset(dist, -1, sizeof dist); dist[person] = 0; q.push(person); while (q.size()) { int x = q.front(); q.pop(); for (auto i: adj[x]) { if (dist[i] != -1) continue; dist[i] = dist[x] + 1; child[x].pb(i); q.push(i); } } bool skip = false; for (int i = 1; i <= N; ++i) { if (dist[i] == -1) skip = true; } if (skip) continue; memset(vis, 0, sizeof vis); vis[person] = 1; dfs(person); int cur = 0; for (auto i: order) { for (auto j: child[i]) dp[i] += dp[j]; ++dp[i]; cur += dp[i]; } ans = min(ans, cur); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...