제출 #1309799

#제출 시각아이디문제언어결과실행 시간메모리
1309799freedommo33Bosses (BOI16_bosses)C++20
100 / 100
722 ms10332 KiB
#include <bits/stdc++.h> #define st first #define nd second #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define mp(a, b) make_pair(a, b) using namespace std; template <typename H, typename T> ostream& operator<<(ostream& os, pair<H, T> p){ return os << "("<<p.st<<","<<p.nd<<")"; } template <typename H> ostream& operator<<(ostream& os, vector<H> v){ os << "{"; for(int i=0; i<sz(v); i++){ if(i) os<<" "; os<<v[i]; } os<<"}"; return os; } void debug() { cerr<<"\n"; } template <typename H, typename... T> void debug(H h, T... t) { cerr<<h; if(sizeof...(t)) cerr<<" "; debug(t...); } #define deb(x...) cerr<<__LINE__<<":"<<#x<<" -> "; debug(x); typedef long long ll; constexpr int M = 2e5+7, INF = 1e9+7, mod = 1e9+7, base = 1<<18; vector<vector<int>> g(M); vector<vector<int>> g2(M); bool odw[M]; int dp[M]; void dfs(int v, int p){ dp[v] = 1; for(auto i:g2[v]) if(i != p){ dfs(i, v); dp[v] += dp[i]; } } void bfs(int v){ queue<int> q; q.push(v); odw[v] = 1; while(!q.empty()){ int p = q.front(); q.pop(); for(auto i:g[p]) if(odw[i] == 0){ odw[i] = 1; g2[p].pb(i); q.push(i); } } } void solve(){ int n; cin>>n; for(int i=1; i<=n; i++){ int a; cin>>a; for(int j=1; j<=a; j++){ int b; cin>>b; g[b].pb(i); } } int wynik = INF; for(int i=1; i<=n; i++){ //cout<<i<<" -> "<<endl; for(int j=1; j<=n; j++){ g2[j].clear(); odw[j] = 0; dp[j] = 0; } bfs(i); bool czy = 0; for(int j=1; j<=n; j++) if(odw[j] == 0){ czy = 1; break; } if(czy == 1) continue; dfs(i, 0); int aktWyn = 0; for(int j=1; j<=n; j++) aktWyn += dp[j]; wynik = min(wynik, aktWyn); } cout<<wynik<<endl; } int main() { cin.tie(0)->sync_with_stdio(0); int t = 1; //cin>>t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...