제출 #522245

#제출 시각아이디문제언어결과실행 시간메모리
522245ddy888Bosses (BOI16_bosses)C++17
100 / 100
1470 ms1000 KiB
#undef _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define int long long #define pb push_back #define fi first #define si second #define ar array typedef pair<int,int> pi; typedef tuple<int,int,int> ti; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);} #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) int N, ans = (1<<30), cur, val[5010]; vector<int> adj[5010], g[5010]; int dfs(int x) { int sum = 0; for (auto i: g[x]) { sum += dfs(i); } val[x] = sum + 1; cur += val[x]; return val[x]; } signed main() { fast; cin >> N; for (int i = 1; i <= N; ++i) { int k; cin >> k; for (int j = 0; j < k; ++j) { int x; cin >> x; adj[x].pb(i); } } for (int i = 1; i <= N; ++i) { vector<int> vis(N + 1, 0); for (int j = 1; j <= N; ++j) g[j].clear(); queue<int> q; q.push(i); vis[i] = 1; while (q.size()) { int x = q.front(); q.pop(); for (auto v: adj[x]) { if (vis[v]) continue; vis[v] = 1; g[x].pb(v); q.push(v); } } int bad = 0; for (int j = 1; j <= N; ++j) bad = max(bad, (long long)!vis[j]); if (bad) continue; cur = 0; dfs(i); ans = min(ans, cur); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...