Submission #937317

#TimeUsernameProblemLanguageResultExecution timeMemory
937317fasdfhasjfaksdfjhalskdjhfBosses (BOI16_bosses)C++14
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<vector<int>> workers(N + 1); for(int i = 1; i <= N; i++){ int K; cin >> K; while(K--){ int x; cin >> x; workers[x].push_back(i); } } int final_ans = INT_MAX; for(int i = 1; i <= N; i++){ queue<pair<int, int>> q; q.push({i, 1}); vector<bool> vis(N + 1, false); vis[i] = 1; int visited = 1; int ans = 0; while(!q.empty()){ pair<int, int> cur = q.front(); q.pop(); for(int j : workers[cur.first]){ if(vis[j]) continue; vis[j] = 1; visited++; ans += (cur.second + 1); q.push({j, cur.second + 1}); } } /*cout << visited << "\n"; for(int j = 1; j <= N; j++){ cout << j << " " << Tree[j].parent << " " << Tree[j].depth << "\nchildren are : "; for(int k : Tree[j].children) cout << k << " "; cout << "\n\n"; } cout << "\n\n==============================\n"; cout << i << " ";*/ if(visited == N){ final_ans = min(final_ans, ans); } else{ cout << "Not valid\n\n\n"; } } cout << final_ans + 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...