Submission #857866

#TimeUsernameProblemLanguageResultExecution timeMemory
857866vjudge1Bosses (BOI16_bosses)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair #define pii pair<int, int> const int maxn = 5e3 + 5; bool mark[maxn]; int cnt[maxn], H_cnt[maxn]; vector<pii > P_pars; vector<int> height[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, root, mx = 0; cin >> n; for (int i = 1; i <= n; i++) { int c; cin >> c; for (int j = 1; j <= c; j++) { int x; cin >> x; P_pars.pb({i, x}); cnt[x]++; if (cnt[x] > mx) { mx = cnt[x]; root = x; } } } // cout << root; height[0].pb(root); mark[root] = true; ll sum = n, dec = 1; for (int i = 1; i <= n; i++) { for (int x: height[i - 1]) { // cout << x << ": "; for (pii u: P_pars) { int v = u.first, par = u.second; if (par == x and v != x and !mark[v]) { // cout << v << ", "; height[i].pb(v); H_cnt[i]++; mark[v] = true; } } // cout << '\n'; } sum += n - dec; dec += H_cnt[i]; } cout << sum; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...