Submission #820253

#TimeUsernameProblemLanguageResultExecution timeMemory
820253tfgsBosses (BOI16_bosses)C++17
100 / 100
431 ms664 KiB
#include <bits/stdc++.h> using namespace std; using pll = pair<long long, long long>; #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back #define eb emplace_back #define f first #define s second template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html template<class Fun> class y_combinator_result { Fun fun_; public: template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {} template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } #ifdef I_AM_NOOB #define gg(...) [](const auto&...x){ char c='='; cerr<<#__VA_ARGS__; ((cerr<<exchange(c,',')<<x),...); cerr<<endl; }(__VA_ARGS__); #else #define gg(...) 777771449 #endif constexpr ll INFF = 1e18; constexpr ll P = 1e9+7; // constexpr ll P = 998244353; int main() { cin.tie(0) -> ios::sync_with_stdio(0); ll n; while (cin >> n) { vector<vector<ll>> children(n+1); for (ll i = 1; i <= n; i++) { ll m; cin >> m; for (ll j = 0; j < m; j++) { ll x; cin >> x; children[x].pb(i); } } gg(children); ll ans = INFF; for (ll i = 1; i <= n; i++) { vector<bool> vis(n+1); vis[i] = true; queue<ll> q; q.push(i); ll lvl = 1, sum = 0; while (!q.empty()) { ll m = q.size(); sum += lvl * m; for (ll j = 0; j < m; j++) { ll u = q.front(); q.pop(); for (auto v : children[u]) { if (vis[v]) continue; vis[v] = true; q.push(v); } } lvl++; } bool valid = true; for (ll i = 1; i <= n; i++) { valid &= vis[i]; } if (valid) ans = min(ans, sum); } cout << ans << endl; } return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:24:17: warning: statement has no effect [-Wunused-value]
   24 | #define gg(...) 777771449
      |                 ^~~~~~~~~
bosses.cpp:43:9: note: in expansion of macro 'gg'
   43 |         gg(children);
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...