# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
858125 |
2023-10-07T12:32:22 Z |
vjudge1 |
Bosses (BOI16_bosses) |
C++17 |
|
418 ms |
860 KB |
//In His Name
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
#define ll long long
#define int ll
#define F first
#define S second
#define pb push_back
#define bug(x) cout << "Ah shit , here we go again : " << x <<endl
#define all(x) x.begin() , x.end()
#define ceil(x,y) x/y + min(1,x%y);
const int maxn = 5000 + 10, MOD = 1e9 + 7;
const ll INF = 1e18;
int n , h[maxn] , ans = INF;
vector<int> adj[maxn];
bool mark[maxn];
void Bfs(int i){
memset(mark , false , sizeof mark);
queue<int> q;
q.push(i);
h[i] = 1;
mark[i] = true;
int sum = 1;
while(!q.empty()){
int v = q.front();
q.pop();
for(int u : adj[v]){
if(!mark[u]){
q.push(u);
mark[u] = true;
h[u] = h[v]+1;
sum += h[u];
}
}
}
for(int j = 1 ; j <= n ; j++) if(!mark[j]) return;
ans = min(sum , ans);
}
main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1 ; i <= n ; i++){
int j;
cin >> j;
for(int l = 1 ; l <= j ; l++){
int x;
cin >> x;
adj[x].pb(i);
}
}
for(int i = 1 ; i <= n ; i++) Bfs(i);
cout << ans;
}
Compilation message
bosses.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
48 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
860 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
75 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
418 ms |
604 KB |
Output is correct |
17 |
Correct |
403 ms |
760 KB |
Output is correct |
18 |
Correct |
401 ms |
604 KB |
Output is correct |