Submission #401546

#TimeUsernameProblemLanguageResultExecution timeMemory
401546GammaBosses (BOI16_bosses)C++14
0 / 100
1 ms332 KiB
#include <bits/stdc++.h>

using namespace std;

long long n, k, ne, head[5005], nxt[10005], to[10005], m, child[5005], mx, mxparent, d[5005], nextt[10005], tt[10005], ans;
bool vis[5005];
priority_queue <pair <long long, long long> > pq;
void AddEdge(long long f, long long t)
{
    nxt[ne] = head[f];
    to[ne] = t;
    head[f] = ne++;
}
long long DFS(long long u)
{
   // if(vis[u]) return 0;
     vis[u] = 1;
     long long e = 0;
     for(long long j = d[u]; ~j; j = nextt[j])
     {
         //cout << ;
         if(!vis[tt[j]])
         {
             e += DFS(tt[j]);
         }
     }
     ans += e;
    // cout << u << ' ' << e << '\n';
     return e + 1;
}
void Addedge(long long f, long long t)
{
    nextt[ne] = d[f];
    tt[ne] = t;
    d[f] = ne++;
}
int main()
{
   // freopen("in.txt", "r", stdin);
    scanf("%lld", &n);
    memset(head, -1, sizeof head);
    for(long long i = 0; i < n; i++)
    {
        scanf("%lld", &k);
        for(long long j = 0; j < k; j++)
        {
            scanf("%lld", &m);
            AddEdge(m, i + 1);
            child[m]++;
            if(child[m] > mx)
            {
                mx = child[m];
                mxparent = m;
            }
        }
    }
    pq.push({0, mxparent});
    vis[mxparent] = 1;
    ne = 0;
    memset(d, -1, sizeof(d));
    while(!pq.empty())
    {
        long long x = pq.top().first, y = pq.top().second;
        pq.pop();
        for(long long g = head[y]; ~g; g = nxt[g])
        {
            if(!vis[to[g]])
            {
                pq.push({x - 1, to[g]});
                vis[to[g]] = 1;
                Addedge(y, to[g]);
            }
        }
    }
    memset(vis, 0, sizeof(vis));
    printf("%lld\n", DFS(mxparent) + ans);
}

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |     scanf("%lld", &n);
      |     ~~~~~^~~~~~~~~~~~
bosses.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |         scanf("%lld", &k);
      |         ~~~~~^~~~~~~~~~~~
bosses.cpp:47:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |             scanf("%lld", &m);
      |             ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...