제출 #164148

#제출 시각아이디문제언어결과실행 시간메모리
164148kostia244Bosses (BOI16_bosses)C++17
67 / 100
1571 ms888 KiB
#define _GLIBCXX_DEBUG #include<bits/stdc++.h> #define pb push_back using namespace std; using ll = long long; using vi = vector<ll>; using vvi = vector<vi>; int n, ans = 1e9, t = 0; vvi g; int d[5050]; int go(int v) { memset(d, -1, sizeof d); queue<int> q; q.push(v); d[v]=1; while(!q.empty()) { int u = q.front(); q.pop(); for(auto v : g[u]) { if(d[v]!=-1) continue; d[v] = d[u]+1; q.push(v); } } ll ans = 0; for(int i = 1; i <= n; i++) if(d[i]==-1) return 1e9; else ans += d[i]; return ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; g.resize(n+1); for(int k, t, i = 1; i <= n; i++) { cin >> k; while(k--) cin >> t, g[t].pb(i); } for(int i = 1; i <= n; i++) { ans = min(ans, go(i)); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...