Submission #755279

#TimeUsernameProblemLanguageResultExecution timeMemory
755279vjudge1Bosses (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; vector <long long> adj[10003]; long long ans = oo * oo; long long bfs(int u, int g){ bool dd[5010]; long long kq[5010]; queue <int> q; int cnt = 0; q.push(u); long long res = 0; for (int i = 1;i <= n;i++) kq[i] = 1; while (!q.empty()){ int u = q.front(); q.pop(); cnt++; dd[u] = true; for (int v : adj[u]){ if (!dd[v]){ dd[v] = true; kq[v] = kq[u] + 1; q.push(v); } } } for (int i = 1;i <= n;i++){ res += kq[i]; } if (cnt < n) return oo; 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...