# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
39779 | nonocut | Bosses (BOI16_bosses) | C++14 | 1500 ms | 2712 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 vis[maxn], cnt;
long long cur, val[maxn];
vector<int> way[maxn], p[maxn];
queue<int> q;
void dfs(int u) {
val[u] = 1;
for(auto v : p[u]) dfs(v), val[u] += val[v];
cur += val[u]; cnt++;
}
ll bfs(int u) {
int i;
memset(vis,0,sizeof(vis));
for(i=1;i<=n;i++) p[i].clear();
vis[u] = 1;
q.push(u);
while(!q.empty()) {
int x = q.front(); q.pop();
for(auto y : way[x]) {
if(!vis[y]) {
vis[y] = 1;
p[x].push_back(y);
q.push(y);
}
}
}
cur = cnt = 0;
dfs(u);
if(cnt==n) return cur;
return inf;
}
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... |