# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
39780 | nonocut | Bosses (BOI16_bosses) | C++14 | 761 ms | 2348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 5e3 + 5;
const long long inf = 1e15;
int n;
int par[maxn], q[maxn];
long long dp[maxn];
vector<int> way[maxn];
ll bfs(int u) {
int i,l,r,x;
memset(par,0,sizeof(par));
memset(dp,0,sizeof(dp));
l = 1; r = 0;
par[u] = u; q[++r] = u;
while(l<=r) {
x = q[l++];
for(auto y : way[x]) {
if(!par[y]) par[y] = x, q[++r] = y;
}
}
long long ret = 0;
for(i=r;i>=1;i--) {
x = q[i]; dp[x]++;
if(i>1) dp[par[x]] += dp[x];
ret += dp[x];
}
if(r<n) return inf;
return ret;
}
int main() {
int i,x,k;
scanf("%d",&n);
for(i=1;i<=n;i++) {
scanf("%d",&k);
while(k--) {
scanf("%d",&x);
way[x].push_back(i);
}
}
ll ans = inf;
for(i=1;i<=n;i++) ans = min(ans, bfs(i));
printf("%lld",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |