제출 #509451

#제출 시각아이디문제언어결과실행 시간메모리
509451ac2huBosses (BOI16_bosses)C++14
0 / 100
0 ms332 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 5e3 + 10; int n; vector<int> adj[N]; int visited[N]; int lev[N]; int dfs(int i){ if(!visited[i]){ int ans = 0; vector<int> temp; visited[i] = true; for(int e : adj[i]){ // cout << 'd' << " " << e << "\n"; if(!visited[e]){ temp.push_back(e); ans += dfs(e); } } // cout << i << "=>> "; // for(int e : temp) // cout << e << " "; // cout << "\n"; lev[i] = ans + 1; return lev[i]; } return 0; } signed main(){ iostream::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); cin >> n; for(int i = 0;i<n;i++){ int c;cin >> c; for(int j = 0;j<c;j++){ int temp;cin >> temp; temp --; adj[i].push_back(temp); } } int ans = 1e18; for(int i = 0;i<n;i++){ // This will the root of the tree for(int i = 0;i<n;i++){ visited[i] =false; lev[i] = -1; } dfs(i); int temp = 0; for(int i = 0;i<n;i++){ // cout << lev[i] << " "; temp += lev[i]; if(!visited[i]){ // cout << i << "\n"; goto next; } } // cout << "\n"; ans = min(ans,temp); next: continue; } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...