Submission #139905

#TimeUsernameProblemLanguageResultExecution timeMemory
1399052fat2codeBosses (BOI16_bosses)C++14
100 / 100
1107 ms852 KiB
#include <bits/stdc++.h> #define ll long long #define all(a) (a).begin(), (a).end() //#pragma GCC optimize("O3") //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define sz() size() #define fr first #define sc second #define pb push_back #define er erase #define in insert #define pi pair<int,int> #define pii pair<pair<int,int>,int> #define mp make_pair //#define int long long #define rc(s) return cout<<s,0 #define rcc(s) cout<<s,exit(0) //#define cin fin //#define cout fout using namespace std; //ifstream fin("file.in"); //ofstream fout("file.out"); const int nmax=1e3+5; const int mod=1e9+7; const int mod1=998244353; int n,t,x,ans=1e9,dp[5005]; bitset<5005>viz; vector<int>cop[5005],nod[5005]; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i=1;i<=n;i++){ cin >> t; for(int j=1;j<=t;j++){ cin >> x; cop[x].push_back(i); } } for(int i=1;i<=n;i++){ viz.reset(); queue<int>q; q.push(i); viz[i]=1; dp[i]=1; int cnt=1; while(!q.empty()){ x=q.front(); for(auto it:cop[x]){ if(!viz[it]){ cnt++; viz[it]=1; q.push(it); dp[it]=dp[x]+1; } } q.pop(); } if(cnt!=n) continue; int rs=0; for(int j=1;j<=n;j++){ rs+=dp[j]; } ans=min(ans,rs); } rc(ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...