Submission #588573

#TimeUsernameProblemLanguageResultExecution timeMemory
588573MohammadAghilBosses (BOI16_bosses)C++17
100 / 100
693 ms664 KiB
#include <bits/stdc++.h> // #pragma GCC optimize ("Ofast,unroll-loops") // #pragma GCC target ("avx2") using namespace std; typedef long long ll; typedef pair<ll, ll> pp; #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl #define per(i,r,l) for(int i = (r); i >= (l); i--) #define rep(i,l,r) for(int i = (l); i < (r); i++) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define pb push_back #define ss second #define ff first void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);} void IOS(){ cin.tie(0) -> sync_with_stdio(0); // #ifndef ONLINE_JUDGE // freopen("in.in", "r", stdin); // freopen("out.out", "w", stdout); // #endif } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll mod = 998244353, maxn = 5e3 + 5, lg = 22, inf = ll(1e9) + 5; ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;} vector<int> adj[maxn]; int dist[maxn], n; ll bfs(int r){ ll ans = 0; fill(dist, dist + n, inf); dist[r] = 1; deque<int> q{r}; int cnt = 0; while(sz(q)){ cnt++; int r = q.front(); q.pop_front(); ans += dist[r]; for(int c: adj[r]) if(dist[c] == inf) dist[c] = dist[r] + 1, q.pb(c); } return cnt == n? ans: inf*inf; } int main(){ IOS(); cin >> n; rep(i,0,n){ int k; cin >> k; rep(j,0,k){ int u; cin >> u; u--; adj[u].pb(i); } } ll ans = inf*inf; rep(i,0,n) ans = min(ans, bfs(i)); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...