Submission #531804

#TimeUsernameProblemLanguageResultExecution timeMemory
531804devariaotaBosses (BOI16_bosses)C++17
0 / 100
1 ms312 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll signed main(){ cin.tie(0) -> ios_base::sync_with_stdio(0); int n; cin >> n; vector<vector<int>> adj(n, vector<int>()); for(int i=0;i<n;i++) { int k; cin >> k; for(int j=0;j<k;j++) { int x; cin >> x; x--; adj[x].push_back(i); } } int mx = 0, r = 0; for(int i=0;i<n;i++) { if(adj[i].size() > mx) { mx = adj[i].size(); r = i; } } queue<int> q; q.push(r); vector<int> g[n]; // real tree vector<int> dist(n, -1), child(n); dist[r] = 0; // cout << "root : " << r << '\n'; while(!q.empty()){ int u = q.front(); q.pop(); for(auto v : adj[u]){ if(dist[v] == -1) { g[v].push_back(u); child[u]++; dist[v] = dist[u] + 1; q.push(v); } } } vector<int> d(n, 1); vector<bool> vis(n); queue<int> q2; for(int i=0;i<n;i++) { if(!child[i]) { q2.push(i); } } while(!q2.empty()){ int x = q2.front(); q2.pop(); // cout << x + 1 << " -> " ; for(auto i : g[x]) { // cout << x + 1 << " -> " << i + 1 << '\n'; q2.push(i); d[i] += d[x]; vis[i] = 1; } } int ans = 0; for(int i=0;i<n;i++) ans += d[i]; cout << ans << '\n'; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:26:26: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   26 |         if(adj[i].size() > mx)
      |            ~~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...