제출 #896129

#제출 시각아이디문제언어결과실행 시간메모리
896129AndreyBosses (BOI16_bosses)C++14
100 / 100
429 ms796 KiB
#include <bits/stdc++.h> using namespace std; vector<int> haha[5001]; int n; int calc(int s) { vector<int> ans(n+1,INT_MAX); ans[s] = 0; queue<int> idk; idk.push(s); while(!idk.empty()) { int a = idk.front(); idk.pop(); for(int v: haha[a]) { if(ans[v] > ans[a]+1) { ans[v] = ans[a]+1; idk.push(v); } } } int sb = 0; for(int i = 1; i <= n; i++) { if(ans[i] == INT_MAX) { return INT_MAX; } sb+=ans[i]+1; } return sb; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; int k,a; for(int i = 1; i <= n; i++) { cin >> k; for(int j = 0; j < k; j++) { cin >> a; haha[a].push_back(i); } } int ans = INT_MAX; for(int i = 1; i <= n; i++) { ans = min(ans,calc(i)); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...