Submission #208107

#TimeUsernameProblemLanguageResultExecution timeMemory
208107w4123Bosses (BOI16_bosses)C++17
22 / 100
5 ms504 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;
    }
    int 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;
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...