# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
79522 |
2018-10-15T01:30:07 Z |
combi1k1 |
Bosses (BOI16_bosses) |
C++14 |
|
1500 ms |
1120 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
const int N = 5e3 + 1;
vector<int> g[N];
int n, p[N];
int nCh[N];
bool vis[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1 ; i <= n ; ++i) {
int s; cin >> s;
while(s--) {
int x; cin >> x;
g[x].push_back(i);
}
}
int ans = 1e18;
for(int i = 1 ; i <= n ; ++i) {
memset(vis,0,sizeof vis);
memset(p,0,sizeof p);
queue<int> q; q.push(i);
vis[i] = 1;
while(q.size()) {
int u = q.front(); q.pop();
for(int v : g[u])
if(!vis[v]) {
p[v] = u;
q.push(v);
vis[v] = 1;
}
}
bool ch = 1;
for(int j = 1 ; j <= n ; ++j) ch &= vis[j];
if (!ch) continue;
int cur = 0;
function<void(int)> dfs = [&](int u) {
nCh[u] = 1;
for(int v : g[u])
if (p[v] == u) {
dfs(v);
nCh[u] += nCh[v];
}
cur += nCh[u];
}; dfs(i);
ans = min(ans,cur);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Correct |
2 ms |
568 KB |
Output is correct |
4 |
Correct |
2 ms |
772 KB |
Output is correct |
5 |
Correct |
2 ms |
804 KB |
Output is correct |
6 |
Correct |
2 ms |
804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Correct |
2 ms |
568 KB |
Output is correct |
4 |
Correct |
2 ms |
772 KB |
Output is correct |
5 |
Correct |
2 ms |
804 KB |
Output is correct |
6 |
Correct |
2 ms |
804 KB |
Output is correct |
7 |
Correct |
3 ms |
804 KB |
Output is correct |
8 |
Correct |
2 ms |
804 KB |
Output is correct |
9 |
Correct |
2 ms |
804 KB |
Output is correct |
10 |
Correct |
3 ms |
804 KB |
Output is correct |
11 |
Correct |
3 ms |
804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Correct |
2 ms |
568 KB |
Output is correct |
4 |
Correct |
2 ms |
772 KB |
Output is correct |
5 |
Correct |
2 ms |
804 KB |
Output is correct |
6 |
Correct |
2 ms |
804 KB |
Output is correct |
7 |
Correct |
3 ms |
804 KB |
Output is correct |
8 |
Correct |
2 ms |
804 KB |
Output is correct |
9 |
Correct |
2 ms |
804 KB |
Output is correct |
10 |
Correct |
3 ms |
804 KB |
Output is correct |
11 |
Correct |
3 ms |
804 KB |
Output is correct |
12 |
Correct |
11 ms |
864 KB |
Output is correct |
13 |
Correct |
12 ms |
864 KB |
Output is correct |
14 |
Correct |
188 ms |
1120 KB |
Output is correct |
15 |
Correct |
37 ms |
1120 KB |
Output is correct |
16 |
Correct |
764 ms |
1120 KB |
Output is correct |
17 |
Execution timed out |
1567 ms |
1120 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |