제출 #779744

#제출 시각아이디문제언어결과실행 시간메모리
779744Sandarach151Bosses (BOI16_bosses)C++17
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> using namespace std; vector<vector<int>> adg; vector<vector<int>> adgtree; void dfs(int cur, long long salary[]){ if(adgtree[cur].empty()){ salary[cur]= (long long) 1; } else{ long long cnt = (long long) 0; for(int next : adgtree[cur]){ dfs(next, salary); cnt+=salary[next]; } salary[cur]=cnt+1; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; adg.resize(n); for(int i=0; i<n; i++){ int a; cin >> a; for(int j=0; j<a; j++){ int b; cin >> b; adg[b-1].push_back(i); } } long long ans = INT64_MAX; for(int root = 0; root<n; root++){ bool vsted[n] = {false}; adgtree.clear(); adgtree.resize(n); queue<int> que; que.push(root); vsted[root]=true; while(!que.empty()){ int cur = que.front(); que.pop(); for(int u : adg[cur]){ if(!vsted[u]){ vsted[u]=true; adgtree[cur].push_back(u); que.push(u); } } } long long salary[n]; dfs(root, salary); long long curans = (long long) 0; for(int i=0; i<n; i++){ curans+=salary[i]; } ans = min(ans, curans); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...