Submission #1040005

#TimeUsernameProblemLanguageResultExecution timeMemory
1040005khanhtbBosses (BOI16_bosses)C++14
0 / 100
3 ms4956 KiB
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 998244353; 
const ll inf = 1e18;
const ll blocksz = 320;
const ll N = 2e5+8;
int n;
ll dp[N],sum[N];
vector<int> g[N];
bool vst[N];
void dfs(int u){
    vst[u] = 1;
    int child = 0;
    for(int v:g[u]){
        if(vst[v]) continue;
        child++;
        dfs(v);
        dp[u] += sum[v];
        sum[u] += sum[v];
    }
    if(!child) dp[u] = 1;
    sum[u] += dp[u];
}
void solve(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        int k;cin >> k;
        for(int j = 1; j <= k; j++){
            int p;cin >> p;
            g[p].pb(i);
        }
    }
    ll ans = inf;
    for(int i = 1; i <= n; i++){
        fill(vst+1,vst+n+1,0);
        fill(dp+1,dp+n+1,0LL);
        dfs(i);
        bool ok = 1;
        for(int j = 1; j <= n; j++) ok &= vst[i];
        ll res = sum[1];
        if(!ok) res = inf;
        ans = min(ans,res);
    }
    cout << ans;
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("test.inp", "r")) {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; i++) {
        solve();
        cout << '\n';
    }
}

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...