# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
825947 |
2023-08-15T09:28:34 Z |
OAleksa |
Bosses (BOI16_bosses) |
C++14 |
|
945 ms |
1032 KB |
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
#define int long long
const int maxn = 5010;
vector<int> g[maxn], t[maxn];
vector<int> vis(maxn), d(maxn);
int ans = 1e18, res;
void dfs(int v) {
for(auto u : t[v]) {
dfs(u);
d[v] += d[u];
}
res += ++d[v];
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while(tt--) {
int n;
cin >> n;
for(int i = 1;i <= n;i++) {
int k;
cin >> k;
for(int j = 1;j <= k;j++) {
int x;
cin >> x;
g[x].push_back(i);
}
}
queue<int> q;
for(int i = 1;i <= n;i++) {
q.push(i);
for(int j = 1;j <= n;j++) {
vis[j] = false;
d[j] = 0;
t[j].clear();
}
vis[i] = 1;
while(!q.empty()) {
auto v = q.front();
q.pop();
for(auto u : g[v]) {
if(vis[u])
continue;
t[v].push_back(u);
q.push(u);
vis[u] = 1;
}
}
res = 0;
dfs(i);
int ok = 1;
for(int j = 1;j <= n;j++)
ok &= (vis[j] == 1);
if(ok)
ans = min(ans, res);
}
cout << ans;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
4 ms |
852 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
254 ms |
944 KB |
Output is correct |
15 |
Correct |
60 ms |
844 KB |
Output is correct |
16 |
Correct |
861 ms |
1032 KB |
Output is correct |
17 |
Correct |
945 ms |
1012 KB |
Output is correct |
18 |
Correct |
912 ms |
1008 KB |
Output is correct |