Submission #171758

#TimeUsernameProblemLanguageResultExecution timeMemory
1717580gnjenBosses (BOI16_bosses)C++14
67 / 100
1570 ms764 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; while(!q.empty()) { int x = q.front(); q.pop(); for(auto j: a[x]) { if(vis[j] == -1) { vis[j] = vis[x]+1; q.push(j); } } } bool moze = true; map<int, int> nivoi; for(int j = 0; j < n; j++) { if(vis[j] == -1) moze = false; nivoi[vis[j]]++; } if(!moze) continue; long long tmpr = 0; for(auto j: nivoi) { tmpr += j.first*j.second; } rez = min(rez, tmpr); } cout << rez; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...