Submission #534925

#TimeUsernameProblemLanguageResultExecution timeMemory
534925vinnipuh01Bosses (BOI16_bosses)C++17
0 / 100
1 ms460 KiB
#include <iostream> #include <bits/stdc++.h> #include <cmath> #include <algorithm> #include <vector> #include <deque> #include <set> #include <stack> #include <string> #include <map> #include <queue> #define int long long using namespace std; const long long oo = 1000000000000000000; long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos; /* ViHHiPuh (( `'-""``""-'` )) )-__-_.._-__-( / --- (o _ o) --- \ \ .-* ( .0. ) *-. / _'-. ,_ '=' _, .-'_ / `;#'#'# - #'#'#;` \ \_)) -----'#'----- ((_/ # --------- # '# ------- ------ #' /..-'# ------- #'-.\ _\...-\'# -- #'/-.../_ ((____)- '#' -(____)) cout << fixed << setprecision(6) << x; ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen ( "sum.in", "r", stdin ) */ vector <int> v[ 10001 ]; int d[ 10001 ], p[ 10001 ]; queue <int> q; bool used[ 100001 ]; int n, col[ 100001 ]; vector <pair<int, int> > vv; int bfs( int x ) { d[ 0 ] = 0; for ( int i = 1; i <= n; i ++ ) { d[ i ] = 1; col[ i ] = 0; used[ i ] = 0; p[ i ] = 0; } q.push( x ); used[ x ] = 1; col[ x ] = 1; while ( q.size() ) { int g = q.front(); q.pop(); for ( auto to : v[ g ] ) { if ( !used[ to ] ) { q.push( to ); col[ to ] = col[ g ] + 1; p[ to ] = g; used[ to ] = 1; } } } vv.clear(); for ( int i = 1; i <= n; i ++ ) { vv.push_back( { col[ i ], i } ); } sort( vv.begin(), vv.end() ); reverse( vv.begin(), vv.end() ); for ( auto i : vv ) { d[ p[ i.second ] ] += d[ i.second ]; } sum = 0; // cout << x << ":"; for ( int i = 1; i <= n; i ++ ) { // cout << i << " - " << p[ i ] << " " << d[ i ] << "\n"; sum += d[ i ]; } // cout << sum << "\n"; return sum; } main () { cin >> n; int k, x; for ( int i = 1; i <= n; i ++ ) { cin >> k; for ( int j = 1; j <= k; j ++ ) { cin >> x; v[ x ].push_back( i ); } } mx = oo; for ( int i = 1; i <= n; i ++ ) { mx = min( mx, bfs( i ) + 0ll ); } cout << mx; }

Compilation message (stderr)

bosses.cpp:95:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   95 | main () {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...