Submission #247688

#TimeUsernameProblemLanguageResultExecution timeMemory
247688WhaleVomitBosses (BOI16_bosses)C++14
100 / 100
818 ms744 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define sz(v) (int)v.size() #define MOO(i, a, b) for(int i=a; i<b; i++) #define M00(i, a) for(int i=0; i<a; i++) #define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--) #define M00d(i,a) for(int i = (a)-1; i>=0; i--) #define FAST ios::sync_with_stdio(0); cin.tie(0); #define finish(x) return cout << x << '\n', 0; #define dbg(x) cerr << ">>> " << #x << " = " << x << "\n"; #define _ << " _ " << template<class T> bool ckmin(T& a, const T& b) {return b < a ? a = b, 1 : 0;} template<class T> bool ckmax(T& a, const T& b) {return a < b ? a = b, 1 : 0;} typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int,int> pi; typedef pair<ld,ld> pd; typedef complex<ld> cd; const int MAX_N = 5010; int n; vi adj[MAX_N]; int main() { FAST cin >> n; M00(i, n) { int k; cin >> k; M00(j, k) { int u; cin >> u; u--; adj[u].pb(i); } } ll bes = 1e18; M00(i, n) { queue<pi> q; vi dis(n, 1e9); vector<bool> vis(n); q.push(mp(i, 0)); dis[i] = 0; while(!q.empty()) { pi p = q.front(); q.pop(); if(vis[p.f]) continue; vis[p.f] = 1; for(int u: adj[p.f]) { if(ckmin(dis[u], dis[p.f]+1)) q.push(mp(u, dis[u])); } } bool valid = 1; M00(j, n) if(dis[j] == 1e9) valid = 0; if(!valid) continue; ll val = 0; M00(j, n) val += dis[j]+1; ckmin(bes, val); } finish(bes); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...