Submission #725560

#TimeUsernameProblemLanguageResultExecution timeMemory
725560Bogdan1110Bosses (BOI16_bosses)C++14
100 / 100
1060 ms1012 KiB
#include <bits/stdc++.h> #define FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);} #define FILES {freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);} #define ll long long #define ull unsigned long long #define pqueue priority_queue #define pb push_back #define fi first #define se second #define ld long double #define pii pair<int,int> #define pll pair<long long,long long> #define all(a) (a).begin(), (a).end() #define mp make_pair using namespace std; // order_of_key -> # less than k // find_by_order -> k-th element // pq max element void files() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } const double eps = 0.00000001; const int NMAX = 5050; const ll inf = LLONG_MAX/3; const ll modi = 998244353; vector<int>al[NMAX]; vector<int>al1[NMAX]; int visited[NMAX]; ll res = 0; int n; void fun(int node){ queue<pii> q; q.push({node,0}); vector<int>ord; while(!q.empty()){ int nd = q.front().fi; int pret = q.front().se; q.pop(); if ( visited[nd] ) { continue; } ord.pb(nd); al1[pret].pb(nd); visited[nd] = 1; for (auto u : al[nd]) { q.push({u,nd}); } } reverse(all(ord)); for (auto nd : ord){ for (auto u : al1[nd]) { visited[nd]+= visited[u]; } res += visited[nd]; } for (int i = 0 ; i <= n ; i++ ) { al1[i].clear(); } } void solve() { cin >> n; for (int i = 1 ; i <= n ; i++ ) { int k; cin >> k; for (int j = 0 ; j < k ; j++ ) { int a; cin >> a; al[a].pb(i); } } ll ans = LLONG_MAX; for (int i = 1 ; i <= n ; i++ ) { memset(visited,0,sizeof(visited)); res = 0; fun(i); for (int j = 1 ; j <= n ; j++ ){ if ( visited[j] == 0 ) res = LLONG_MAX; } ans = min(ans,res); } cout << ans << endl; } int main () { FAST int t=1; /* cin >> t; //*/ int i = 1; while(t--) { //cout << "Case #" << i++ << ": " ; solve(); } }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:108:9: warning: unused variable 'i' [-Wunused-variable]
  108 |     int i = 1;
      |         ^
bosses.cpp: In function 'void files()':
bosses.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...