# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
46546 |
2018-04-21T11:32:15 Z |
ista2000 |
Bosses (BOI16_bosses) |
C++17 |
|
1500 ms |
1856 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long int
vector< vector<int> > v, g;
vector<int> a;
int n;
void dfs(int u, int p)
{
a[u] = 1;
for(int i: g[u])
if(i!=p)
dfs(i, u), a[u]+=a[i];
}
int bfs(int r)
{
queue< pair<int, int> > q;
q.push(make_pair(r, r));
g.clear();
g.resize(n);
a.clear();
a.resize(n);
vector<int> vis(n);
while(!q.empty())
{
int cur = q.front().first;
int curp = q.front().second;
q.pop();
if(vis[cur])continue;
vis[cur] = 1;
g[cur].push_back(curp);
g[curp].push_back(cur);
for(int i: v[cur])
q.push(make_pair(i, cur));
}
bool done = true;
for(int i = 0;i<n;i++)
if(!vis[i])
done = false;
if(!done)return INT_MAX;
dfs(r, r);
return accumulate(a.begin(), a.end(), 0ll);
}
#undef int
int main()
{
#define int long long int
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
v.resize(n);
for(int i = 0;i<n;i++)
{
int k;
cin>>k;
for(int j = 0;j<k;j++)
{
int x;
cin>>x;
x--;
v[x].push_back(i);
}
}
int ans = INT_MAX;
for(int i = 0;i<n;i++)
ans = min(ans, bfs(i));
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
4 |
Correct |
2 ms |
652 KB |
Output is correct |
5 |
Correct |
2 ms |
656 KB |
Output is correct |
6 |
Correct |
2 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
4 |
Correct |
2 ms |
652 KB |
Output is correct |
5 |
Correct |
2 ms |
656 KB |
Output is correct |
6 |
Correct |
2 ms |
768 KB |
Output is correct |
7 |
Correct |
2 ms |
808 KB |
Output is correct |
8 |
Correct |
2 ms |
812 KB |
Output is correct |
9 |
Correct |
2 ms |
816 KB |
Output is correct |
10 |
Correct |
3 ms |
820 KB |
Output is correct |
11 |
Correct |
3 ms |
824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
4 |
Correct |
2 ms |
652 KB |
Output is correct |
5 |
Correct |
2 ms |
656 KB |
Output is correct |
6 |
Correct |
2 ms |
768 KB |
Output is correct |
7 |
Correct |
2 ms |
808 KB |
Output is correct |
8 |
Correct |
2 ms |
812 KB |
Output is correct |
9 |
Correct |
2 ms |
816 KB |
Output is correct |
10 |
Correct |
3 ms |
820 KB |
Output is correct |
11 |
Correct |
3 ms |
824 KB |
Output is correct |
12 |
Correct |
41 ms |
1084 KB |
Output is correct |
13 |
Correct |
32 ms |
1220 KB |
Output is correct |
14 |
Correct |
1319 ms |
1856 KB |
Output is correct |
15 |
Correct |
121 ms |
1856 KB |
Output is correct |
16 |
Execution timed out |
1575 ms |
1856 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |