# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
79544 | MoesashiMinamoto | Bosses (BOI16_bosses) | C++14 | 1561 ms | 1300 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;
int n;
vector< int > acc[5003];
int m;
int vis[5003];
int pa[5003];
vector<int> g[5003];
int sal[5003];
long long dfs(int u, int root) {
if (u == root) {
for (int i = 1; i <= n; i++) {
sal[i] = 1ll*n*(n-1)/2;
}
}
long long res = 1;
for (auto v : g[u]) {
res += dfs(v, root);
}
sal[u] = res;
if (u != root) return res;
else {
res = 0;
for (int i = 1; i <= n; i++) {
res += sal[i];
}
return res;
}
}
long long fouck(int pos) {
queue<int> q;
q.push(pos);
memset(vis, 0, sizeof(vis));
vis[pos] = 1;
for (int i = 1; i <= n; i++) {
g[i].clear();
}
while (!q.empty()) {
int u = q.front(); q.pop();
for (auto v : acc[u]) {
if (!vis[v]) {
q.push(v);
g[u].push_back(v);
vis[v] = 1;
}
}
}
return dfs(pos, pos);
}
signed main() {
int x, y;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &m);
for (int j = 1; j <= m; j ++) {
scanf("%d", &x);
acc[x].push_back(i);
}
}
long long res = LLONG_MAX;
for (int i = 1; i <= n; i++) {
res = min(res, fouck(i));
}
cout << res;
}
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... |