제출 #815387

#제출 시각아이디문제언어결과실행 시간메모리
815387NguyenKhangBosses (BOI16_bosses)C++17
100 / 100
928 ms980 KiB
//#pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC target("bmi,bmi2,lzcnt,popcnt") //#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native") //#pragma expected_value //#pragma isolated_call //#pragma disjoint #include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //using namespace __gnu_pbds; using namespace std; //#define int long long //#define double long double #define Fi first #define Se second #define Rep(i,a,b) for (int i=a;i<=b;++i) #define Repu(i,b,a) for (int i=b;i>=a;--i) #define pb push_back #define ms(a,i) memset(a,i,sizeof(a)) #define sz size() #define mp make_pair #define endl '\n' #define sef setprecision(6)<<fixed #define cer cout<<"cak"<<endl; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<double> va; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<va> vva; //const double EPS=1e-9; const double PI=acos(-1); const long long oo=1e18; const int MN=5000+5; const int mod=1e9+7; using cd=complex<double>; //typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> index_set; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n; vi adj[MN]; int visited[MN]; vi G[MN]; int dp[MN]; int res; bool bfs(int x) { res = 0; Rep(i,1,n) { visited[i] = 0; dp[i] = 0; G[i].clear(); } queue<int> Q; Q.push(x); visited[x] = 1; int comp = n-1; while(!Q.empty()) { int u = Q.front(); Q.pop(); for(int v:adj[u]) { if(visited[v]) continue; comp--; visited[v] = 1; Q.push(v); G[u].pb(v); } } return (comp == 0); } void solve(int u,int pre) { dp[u] = 1; for(int v:G[u]) { if(v==pre) continue; solve(v,u); dp[u] += dp[v]; } res += dp[u]; } signed main() { //freopen(".inp","r",stdin); freopen(".out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; Rep(i,1,n) { int k; cin>>k; while(k--) { int x; cin>>x; adj[x].pb(i); } } // root int ans = mod; Rep(root,1,n) { if(!bfs(root)) continue; solve(root,root); ans = min(ans,res); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...