Submission #951512

#TimeUsernameProblemLanguageResultExecution timeMemory
951512Sir_Ahmed_ImranBosses (BOI16_bosses)C++17
0 / 100
1 ms348 KiB
///~~~LOTA~~~/// #include <bits/stdc++.h> using namespace std; #define ll long long #define li long int #define ld long double #define append push_back #define add insert #define nl '\n' #define ff first #define ss second #define pii pair<int,int> #define pic pair<int,char> #define all(x) (x).begin(),(x).end() #define sum(a) accumulate(all(a),0) #define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define terminator main #define N 5001 int n; int vis[N]; vector<int> a[N]; int bfs(int x){ int o,r; o=0; vis[x]=r=1; vector<int> v{x},u; while(!v.empty()){ o+=r*v.size(); for(auto& i:v){ for(auto& j:a[i]){ if(vis[j]) continue; u.append(j); vis[j]=1; } } swap(v,u); u.clear(); r++; } for(int i=1;i<=n;i++) vis[i]=0; return o; } void solve(){ int m,o; cin>>n; for(int i=1;i<=n;i++){ cin>>m; while(m--){ cin>>o; a[o].append(i); } } o=1e9; for(int i=1;i<=n;i++) o=min(o,bfs(i)); cout<<o; } int terminator(){ L0TA; solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...