Submission #401537

#TimeUsernameProblemLanguageResultExecution timeMemory
401537GammaBosses (BOI16_bosses)C++14
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; int 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 <int, int> > pq; void AddEdge(int f, int t) { nxt[ne] = head[f]; to[ne] = t; head[f] = ne++; } int DFS(int u) { // if(vis[u]) return 0; vis[u] = 1; int e = 0; for(int 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(int f, int t) { nextt[ne] = d[f]; tt[ne] = t; d[f] = ne++; } int main() { //freopen("in.txt", "r", stdin); scanf("%d", &n); memset(head, -1, sizeof head); for(int i = 0; i < n; i++) { scanf("%d", &k); for(int j = 0; j < k; j++) { scanf("%d", &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()) { int x = pq.top().first, y = pq.top().second; pq.pop(); for(int 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("%d\n", DFS(mxparent) + ans); }

Compilation message (stderr)

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