Submission #485982

#TimeUsernameProblemLanguageResultExecution timeMemory
485982chungdinhBosses (BOI16_bosses)C++17
100 / 100
792 ms660 KiB
#include <iostream> #include <utility> #include <cstring> #include <vector> #include <queue> #include <stack> using namespace std; #define ii pair<int, int> #define ll long long #define MP(x, y) make_pair(x, y) const int N = 5e3 + 5; const ll INF = 1e18; int n; vector<int> g[N]; bool vsd[N]; ll dp[N]; vector<int> lst; ll bfs(int u) { ll res = 0; queue<int> q; q.push(u); memset(vsd, false, sizeof vsd); vsd[u] = true; memset(dp, 0ll, sizeof dp); dp[u] = 1; while (q.size()) { int u = q.front(); q.pop(); res += dp[u]; for (int v : g[u]) { if (!vsd[v]) { vsd[v] = true; q.push(v); dp[v] = dp[u] + 1; } } } for (int i = 1; i <= n; i++) if (!vsd[i]) return INF; return res; } int main() { #ifdef CHUNGDINH freopen("main.inp", "r", stdin); #endif // CHUNGDINH cin >> n; for (int i = 1; i <= n; i++) { int k; cin >> k; while (k--) { int u; cin >> u; g[u].push_back(i); } } ll res = INF; for (int i = 1; i <= n; i++) res = min(res, bfs(i)); cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...