# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
349313 |
2021-01-17T11:40:13 Z |
S2speed |
Bosses (BOI16_bosses) |
C++17 |
|
710 ms |
768 KB |
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#pragma GCC optimize ("Ofast")
#define all(x) x.begin() , x.end()
#define gcd __gcd
typedef long long int ll;
typedef pair<ll , ll> pll;
typedef pair<int , int> pii;
typedef long double db;
typedef pair<ll , pll> plll;
typedef pair<int , pii> piii;
const ll MAXN = 5e3 + 20 , md = 1e9 + 7;
// check problem statement
vector<int> adj[MAXN] , bfs;
int dis[MAXN];
int main(){ // check MAXN
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n , ans = 1e8;
cin>>n;
for(int i = 0 ; i < n ; i++){
ll k;
cin>>k;
for(int j = 0 ; j < k ; j++){
ll v;
cin>>v; v--;
adj[v].push_back(i);
}
}
for(int i = 0 ; i < n ; i++){
memset(dis , 63 , sizeof(dis));
dis[i] = 1;
int x = 0 , h = 0;
bfs.push_back(i);
while(x < bfs.size()){
int v = bfs[x];
for(auto u : adj[v]){
if(dis[u] > dis[v] + 1){
dis[u] = dis[v] + 1;
bfs.push_back(u);
}
}
x++;
}
bfs.clear();
for(int j = 0 ; j < n ; j++){
if(dis[j] > n){
h = 1e8;
break;
}
h += dis[j];
}
ans = min(ans , h);
}
cout<<ans<<'\n';
return 0;
}
/*
*/
Compilation message
bosses.cpp: In function 'int main()':
bosses.cpp:42:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | while(x < bfs.size()){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
4 ms |
620 KB |
Output is correct |
13 |
Correct |
3 ms |
620 KB |
Output is correct |
14 |
Correct |
105 ms |
620 KB |
Output is correct |
15 |
Correct |
6 ms |
620 KB |
Output is correct |
16 |
Correct |
537 ms |
768 KB |
Output is correct |
17 |
Correct |
710 ms |
748 KB |
Output is correct |
18 |
Correct |
698 ms |
748 KB |
Output is correct |