제출 #958397

#제출 시각아이디문제언어결과실행 시간메모리
958397IsaLBosses (BOI16_bosses)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define fi first #define se second #define pii pair<int, int> #define pll pair<ll, ll> const int N = 5069; const ll mod = 1e9 + 7; int tc; int n, sub[N], cn, tot; bool vis[N]; vector<int> al[N]; void dfs(int x) { ++cn; sub[x] = 1; vis[x] = 1; for(auto z : al[x]) { if(vis[z]) continue; dfs(z); sub[x] += sub[z]; } tot += sub[x]; } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int i, j; cin >> n; for(i = 1; i <= n; i++) { int k; cin >> k; for(j = 1; j <= k; j++) { int x; cin >> x; al[x].push_back(i); } } int ans = 1e9; for(i = 1; i <= n; i++) { cn = tot = 0; for(j = 1; j <= n; j++) { sub[j] = 0; vis[j] = 0; } dfs(i); if(cn == n) ans = min(ans, tot); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...