# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41138 | ssnsarang2023 | Bosses (BOI16_bosses) | C++14 | 1530 ms | 1628 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 <cstdio>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(x) ((int)x.size())
const int N = 5e3+5;
int n, sz[N];
bool vis[N];
vector<int> g[N], g2[N];
void dfs(int u, int &total) {
sz[u] = 1;
for (int v : g2[u]) {
dfs(v, total);
sz[u] += sz[v];
}
total += sz[u];
}
int make_tree(int root) {
for (int i = 1; i <= n; ++i) vis[i] = false, g2[i].clear();
queue<int> q;
q.push(root);
vis[root] = 1;
int cnt = 1;
while (SZ(q)) {
int u = q.front(); q.pop();
for (int v : g[u]) {
if (vis[v]) continue;
++cnt, vis[v] = true;
q.push(v);
g2[u].push_back(v);
}
}
if (cnt < n) return (int)1e9+7;
int sum = 0;
dfs(root, sum);
return sum;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
int m; scanf("%d", &m);
for (int j = 1, v; j <= m; ++j) {
scanf("%d", &v);
g[v].push_back(i);
}
}
int res = (int)1e9+7;
for (int i = 1; i <= n; ++i)
res = min(res, make_tree(i));
printf("%d", res);
return 0;
}
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... |