제출 #208109

#제출 시각아이디문제언어결과실행 시간메모리
208109w4123Bosses (BOI16_bosses)C++17
0 / 100
5 ms376 KiB
#include <iostream> #include <string> #include <vector> #include <queue> #include <algorithm> bool used[5001]; using namespace std; int main() { int n; cin >> n; vector<int> v[5001]; 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 great_index = 1; for (int i = 2; i <= n; i++) { if (v[i].size() >= v[great_index].size()) great_index = i; } long long ans = 0; queue<pair<int, int>> q; q.push(make_pair(1, great_index)); used[great_index] = true; while (!q.empty()) { 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(); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...