# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
884345 |
2023-12-07T07:55:40 Z |
vjudge1 |
Bosses (BOI16_bosses) |
C++17 |
|
1 ms |
360 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pll array<ll, 2>
const int N = 5e3 + 4;
const ll INF = 1ll << 62;
int n;
bool vis[N];
vector<int> in[N];
pll dfs(int v) {
vis[v] = true;
pll ret = {0, 0};
for (int u : in[v]) {
if (vis[u] == false) {
pll res = dfs(u);
ret[0] += res[0];
ret[1] += res[1];
}
}
++ret[0];
ret[1] += ret[0];
return ret;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
while (k--) {
int v;
cin >> v;
--v;
in[v].pb(i);
}
}
ll ans = INF;
for (int i = 0; i < n; ++i) {
pll res = dfs(i);
bool seeAll = true;
for (int j = 0; j < n; ++j) {
seeAll &= vis[j];
vis[j] = false;
}
if (seeAll == true) {
ans = min(ans, res[1]);
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
360 KB |
Output is correct |
2 |
Incorrect |
1 ms |
352 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
360 KB |
Output is correct |
2 |
Incorrect |
1 ms |
352 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
360 KB |
Output is correct |
2 |
Incorrect |
1 ms |
352 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |