# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36400 | DoanPhuDuc | Bosses (BOI16_bosses) | C++98 | 1500 ms | 2684 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>
#define FOR(x, a, b) for (int x = a; x <= b; ++x)
#define FOD(x, a, b) for (int x = a; x >= b; --x)
#define REP(x, a, b) for (int x = a; x < b; ++x)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A, n) { cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl; }
#define PR0(A, n) { cout << #A << " = "; REP(_, 0, n) cout << A[_] << " "; cout << endl; }
using namespace std;
typedef long long LL;
typedef pair <int, int> II;
const int N = 5e3 + 10;
const int INF = 0x3f3f3f3f;
int n;
int f[N];
bool ban[N];
vector <int> boss[N], adj[N];
void DFS(int u) {
f[u] = 1;
REP(k, 0, adj[u].size()) {
int v = adj[u][k];
DFS(v);
f[u] += f[v];
}
}
int Compute(int u) {
FOR(i, 1, n) {
ban[i] = false;
adj[i].clear();
}
queue <int> Q1, Q2; Q1.push(u); Q2.push(u);
ban[u] = true;
while (Q1.size()) {
while (Q2.size()) {
int u = Q2.front(); Q2.pop(); Q1.pop();
REP(k, 0, boss[u].size()) {
int v = boss[u][k];
if (ban[v] == false) {
ban[v] = true;
Q1.push(v);
adj[u].push_back(v);
}
}
}
Q2 = Q1;
}
int num = 0;
FOR(i, 1, n) num += ban[i];
if (num == n) {
DFS(u);
int ans = 0;
FOR(i, 1, n) ans += f[i];
return ans;
} else return INF;
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
scanf("%d", &n);
FOR(i, 1, n) {
int m; scanf("%d", &m);
FOR(j, 1, m) {
int x; scanf("%d", &x);
boss[x].push_back(i);
}
}
int ans = INF;
FOR(i, 1, n) ans = min(ans, Compute(i));
printf("%d\n", ans);
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... |