Submission #985347

# Submission time Handle Problem Language Result Execution time Memory
985347 2024-05-17T16:28:53 Z ionut2212 Bosses (BOI16_bosses) C++17
100 / 100
449 ms 856 KB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
vector<vector<int > > v;
int viz[10011];
/*int suma(int poz)
{
    if(sum[poz] == 0)
    {
        if(nivel[poz].size() == 0)
            return 1;
        else
            return 1 +
    }
}*/
int main()
{
    int n;
    cin >> n;
    v.resize(n+1);
    for(int i = 1; i<=n; i++)
    {
        int x;
        cin >> x;
        for(int j = 1; j<=x; j++)
        {
            int y;
            cin >> y;
            v[y].push_back(i);
        }
    }
    int sum, minim = 1e9 + 1e9;
    for(int j = 1; j<=n; j++)
    {
        queue<int> q;
        q.push(j);
        viz[j] = 1;
        sum = 1;
        int s = 0;
        while(!q.empty())
        {
            int nod = q.front();
            for(int i = 0; i < v[nod].size(); i++)
            {
                int vecin = v[nod][i];
                if(!viz[vecin])
                {
                    s++;
                    viz[vecin] = viz[nod] + 1;
                    sum+=viz[vecin];
                    q.push(vecin);
                }
            }
            //cout << nod << ' ';
            q.pop();
        }
        //cout <<' '<< sum << '\n';
        if(s == n-1)
            minim = min(minim, sum);
        for(int i = 1; i <= n; i++) viz[i] = 0;
    }
    cout << minim;
    return 0;
}
/// smin => noduri cu cat mai multe elemente

Compilation message

bosses.cpp: In function 'int main()':
bosses.cpp:45:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |             for(int i = 0; i < v[nod].size(); i++)
      |                            ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 79 ms 856 KB Output is correct
15 Correct 4 ms 604 KB Output is correct
16 Correct 449 ms 604 KB Output is correct
17 Correct 412 ms 772 KB Output is correct
18 Correct 417 ms 776 KB Output is correct