Submission #755188

#TimeUsernameProblemLanguageResultExecution timeMemory
755188vjudge1Bosses (BOI16_bosses)C++17
0 / 100
1 ms596 KiB
///***LTT***/// /// ->TUYEN QUOC GIA<- /// #include<bits/stdc++.h> #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #pragma GCC target("popcnt") //#define int long long #define F first #define S second #define pb push_back #define CHECKBIT(mask,i) ((mask>>(i) )&1) // == 1 la bat, == 0 la tat #define OFFBIT(mask,i) ((1<<(i))^mask) // tat bit thu i #define ONBIT(mask,i) ((1<<(i))mask) // bat bit thu i using namespace std; const long long oo = 1e9+7; const int N = 2 * 1e5 + 10; int n, p, k, parent[5003][5003]; vector <long long> adj[5003]; bool dd[5002][5002]; long long ans = oo, child[5003][5003], kq[5003][5003], tam[5003][5003]; long long bfs(int u, int g){ queue <int> q; q.push(u); long long res = 0; while (!q.empty()){ int u = q.front(); q.pop(); dd[g][u] = true; for (int v : adj[u]){ if (!dd[g][v]){ dd[g][v] = true; q.push(v); child[g][u]++; parent[g][v] = u; } } if(child[g][u] == 0){ // if (g == 4){ // cout <<" c " << u << "\n"; // } kq[g][u] = 1; tam[g][u] = 1; while(u != g){ tam[g][parent[g][u]] += kq[g][u]; if (kq[g][parent[g][u]] <= tam[g][parent[g][u]]) kq[g][parent[g][u]] = tam[g][parent[g][u]] + 1; u = parent[g][u]; } } } // if (g == 4){ // for (int i = 1;i <= n;i++){ // cout << i <<" "<< kq[g][i] <<"\n"; // } // } for (int i = 1;i <= n;i++){ res += kq[g][i]; } // cout << g <<" " << res << endl; return res; } void inp(){ cin >> n; for (int i = 1;i <= n;i++){ cin >> k; for (int j = 1;j <= k;j++){ cin >> p; adj[p].pb(i); } } for (int i = 1;i <= n;i++){ ans = min(ans,bfs(i,i)); } cout << ans; return; } void solve(){ return; } int main(){ ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); // freopen("in.inp", "r", stdin); // freopen("in.out", "w", stdout); inp(); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...