Submission #886762

#TimeUsernameProblemLanguageResultExecution timeMemory
886762BBart888Bosses (BOI16_bosses)C++14
100 / 100
915 ms1364 KiB
#include <cstdio> #include <iostream> #include <vector> #include <list> #include <string> #include <set> #include <map> #include <algorithm> #include <fstream> #include <cmath> #include <queue> #include <stack> #include <cassert> #include <cstring> #include <climits> #include <functional> #include<cstdlib> //#include "arc.h" using namespace std; typedef pair<int, int> PII; typedef vector<int> VI; typedef long long LL; const int MAXN = 5e3 + 11; using ll = long long; typedef vector<int> lnum; const int base = 1e9; const ll mod1 = 1e9 + 7; const ll mod2 = 1000000021; const ll P = 31; /* void setIO(string name = "") { cin.tie(0)->sync_with_stdio(0); // see /general/fast-io if ((name.size())) { freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output freopen((name + ".out").c_str(), "w", stdout); } } */ int n; vector<int> adj[MAXN]; vector<int> lst[MAXN]; bool used[MAXN]; int sz = 0; ll num[MAXN]; ll ans = 1e18; void calc(int v, int p) { sz++; ll sum = 0; for (auto u : adj[v]) { if (u == p) continue; calc(u, v); sum += num[u]; } num[v] = sum + 1; } void build(int v, int p) { used[v] = true; queue<int> q; q.push(v); while (!q.empty()) { int x = q.front(); q.pop(); for (auto u : lst[x]) { if (used[u]) continue; adj[u].push_back(x); adj[x].push_back(u); used[u] = true; q.push(u); } } } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); //setIO("time"); cin >> n; for (int i = 1; i <= n; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int v; cin >> v; lst[v].push_back(i); } } for (int root = 1; root <= n; root++) { for (int i = 1; i <= n; i++) { adj[i].clear(); used[i] = num[i] = 0; sz = 0; } build(root, root); calc(root, root); ll curr = 0; for (int i = 1; i <= n; i++) curr += num[i]; if (sz == n) ans = min(ans, curr); } cout << ans << '\n'; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:122:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
  122 |    used[i] = num[i] = 0;
      |              ~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...