Submission #813288

#TimeUsernameProblemLanguageResultExecution timeMemory
813288trucmaiBosses (BOI16_bosses)C++17
100 / 100
476 ms24068 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "/home/trucmai/.vim/tools.h" #define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl; #else #define debug(x...) #endif void open(){ if(fopen("i.inp","r")){ freopen("i.inp","r",stdin); freopen("o.out","w",stdout); } } #define ll long long #define all(a) (a).begin(), (a).end() #define vi vector<ll> #define pi pair<ll,ll> #define pii pair<ll,pair<ll,ll>> #define fi first #define se second #define gcd __gcd #define mset(a,v) memset(a, v, sizeof(a)) #define endl '\n' #define spc " " const int MN = 1e6 + 5,LOG = 27; const ll MOD = 1e9 + 7,INF = 1e9; ll n; vector<ll>g[MN]; ll bfs(ll root){ queue<ll>qu; ll res = 0; vector<ll>h(n+1,0); vector<bool>vis(n+1,false); h[root] = 1; qu.push(root); vis[root] = true; while(!qu.empty()){ ll u = qu.front(); qu.pop(); res += h[u]; for(ll &v : g[u]){ if(vis[v]) continue; h[v] = h[u] + 1; vis[v] = true; qu.push(v); } } bool flag = true; for(ll i = 1;i <= n;++i) flag &= vis[i]; return (flag ? res : INF); } void solve(){ cin>>n; for(ll i = 1;i <= n;++i){ ll k; cin>>k; for(ll j = 1;j <= k;++j){ ll x; cin>>x; g[x].push_back(i); } } ll res = INF; for(ll r = 1;r <= n;++r) res = min(res,bfs(r)); cout<<res<<endl; } signed main(){ cin.tie(0) -> sync_with_stdio(0); open(); ll t = 1; //cin>>t; while(t--) solve(); #ifdef LOCAL cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif }

Compilation message (stderr)

bosses.cpp: In function 'void open()':
bosses.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen("i.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
bosses.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen("o.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...