Submission #171760

#TimeUsernameProblemLanguageResultExecution timeMemory
1717600gnjenBosses (BOI16_bosses)C++14
0 / 100
2 ms256 KiB
//Failure will never overtake me if my determination to succeed is strong enough #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a[n]; for(int i = 0; i < n; i++) { int m; cin >> m; while(m--) { int x; cin >> x; a[x-1].push_back(i); } } long long rez = INT_MAX; for(int i = 0; i < n; i++) { int vis[n]; for(int j = 0; j < n; j++) vis[j] = -1; queue<int> q; q.push(i); vis[i] = 1; int maxn = 1; while(!q.empty()) { int x = q.front(); q.pop(); for(auto j: a[x]) { if(vis[j] == -1) { vis[j] = vis[x]+1; maxn = max(maxn, vis[j]); q.push(j); } } } bool moze = true; int nivoi[maxn+1]; for(int j = 0; j < n; j++) { if(vis[j] == -1) moze = false; nivoi[vis[j]]++; } if(!moze) continue; long long tmpr = 0; for(int j = 1; j <= maxn; j++) { tmpr += j*nivoi[j]; } rez = min(rez, tmpr); } cout << rez; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...