Submission #1129754

#TimeUsernameProblemLanguageResultExecution timeMemory
1129754LudisseyBosses (BOI16_bosses)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h> #define int long long #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() using namespace std; vector<vector<int>> child; int s=0; int dfs(int x){ int sm=0; for (auto u : child[x]) { sm+=dfs(u); } s+=sm+1; return sm+1; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<vector<int>> neigh(n); child.resize(n); for (int i = 0; i < n; i++) { int k; cin >> k; for (int j = 0; j < n-1; j++) { int x; cin >> x; neigh[x-1].push_back(i); } } int mn=1e18; for (int i = 0; i < n; i++) { vector<int> dist(n,1e18); vector<bool> visited(n); for (int j = 0; j < n; j++) child[j].clear(); dist[i]=0; queue<int> queue; queue.push(i); while(!queue.empty()){ int x=queue.front(); queue.pop(); if(visited[x]) continue; visited[x]=true; for (auto u : neigh[x]) { if(dist[u]>dist[x]+1){ dist[u]=dist[x]+1; child[x].push_back(u); queue.push(u); } } } bool b=false; for (int j = 0; j < n; j++) { if(!visited[j]) b=true; } if(b) continue; s=0; dfs(i); mn=min(s,mn); } cout << mn << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...