Submission #208120

#TimeUsernameProblemLanguageResultExecution timeMemory
208120w4123Bosses (BOI16_bosses)C++17
100 / 100
803 ms760 KiB
#include <iostream> #include <string> #include <vector> #include <queue> #include <algorithm> #include <cstring> using namespace std; bool used[5001]; vector<int> v[5001]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { int num; cin >> num; for (int j = 1; j <= num; j++) { int tmp; cin >> tmp; v[tmp].push_back(i); } } /* int greatest = 0; vector<int> great_index; for (int i = 1; i <= n; i++) { if (v[i].size() > greatest) { greatest = v[i].size(); great_index.clear(); great_index.push_back(i); } else if (v[i].size() == greatest) { great_index.push_back(i); } }*/ long long res = 9999999999999; for (int g = 1; g <= n; g++) { long long ans = 0; memset(used, 0, sizeof(bool) * 5001); queue<pair<int, int>> q; q.push(make_pair(1, g)); used[g] = true; int count = 0; while (!q.empty()) { count++; ans += q.front().first; for (const auto& c : v[q.front().second]) { if (!used[c]) { q.push(make_pair(q.front().first + 1, c)); used[c] = true; } } q.pop(); } if (count != n)continue; if (ans < res) res = ans; } cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...