Submission #857986

#TimeUsernameProblemLanguageResultExecution timeMemory
857986vjudge1Bosses (BOI16_bosses)C++17
67 / 100
1562 ms984 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, maxk = 1e4 + 5; bool mark[maxn]; int H_cnt[maxn], n; vector<pii > P_pars; int calc(int root) { vector<int> height[maxn]; memset(H_cnt, 0, sizeof H_cnt); memset(mark, false, sizeof mark); height[0].pb(root); H_cnt[0] = 1; mark[root] = true; ll sum = n, dec = 1; for (int i = 1; i < n; i++) { for (int x: height[i - 1]) { for (pii u: P_pars) { int v = u.first, par = u.second; if (par == x and v != x and !mark[v]) { height[i].pb(v); H_cnt[i]++; mark[v] = true; } } } sum += n - dec; dec += H_cnt[i]; } return sum; } inline int minn(ll a, ll b) { if(a <= b) return a; else return b; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int mx = 0; vector<int> roots; 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}); } } ll ans = 1e18; for (int i = 1; i <= n; i++) { ans = minn(ans, calc(i)); } cout << ans; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:51:9: warning: unused variable 'mx' [-Wunused-variable]
   51 |     int mx = 0;
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...