Submission #231531

#TimeUsernameProblemLanguageResultExecution timeMemory
231531Haunted_CppBosses (BOI16_bosses)C++17
100 / 100
703 ms760 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize ("Ofast") #pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") const int N = 5e3 + 5; vector< vector<int> > g (N); int main () { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int st; cin >> st; --st; g[st].emplace_back(i); } } queue<int> q; int mn = 1e9; for (int i = 0; i < n; i++) { vector<int> dist (N, 1e9); int visited = 0; int res = 1; dist[i] = 1; q.push(i); while (!q.empty()) { int node = q.front(); ++visited; q.pop(); for (auto to : g[node]) { if (dist[to] > dist[node] + 1) { dist[to] = dist[node] + 1; res += dist[to]; q.push(to); } } } if (visited != n) continue; mn = min (mn, res); } cout << mn << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...