# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
485802 |
2021-11-09T11:56:13 Z |
radal |
Bosses (BOI16_bosses) |
C++14 |
|
666 ms |
680 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC target("avx2,fma")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
typedef pair<long double,long double> pld;
const long long int N = 5e3+10,mod = 998244353,inf = 1e18,maxm = (1 << 24);
inline int mkay(int a,int b){
if (a+b >= mod) return a+b-mod;
if (a+b < 0) return a+b+mod;
return a+b;
}
inline int poww(int n,ll k){
int c = 1;
while (k){
if (k&1) c = (1ll*c*n)%mod;
n = (1ll*n*n)%mod;
k >>= 1;
}
return c;
}
int sz[N],d[N];
vector<int> adj[N];
bool vis[N];
void bfs(int v){
d[v] = 0;
vis[v] = 1;
queue <int> q;
q.push(v);
while (!q.empty()){
int u = q.front();
q.pop();
for (int w : adj[u]){
if (!vis[w]){
q.push(w);
d[w] = d[u]+1;
vis[w] = 1;
}
}
}
}
int main(){
ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin >> n;
rep(i,1,n+1){
cin >> sz[i];
rep(j,0,sz[i]){
int u;
cin >> u;
adj[u].pb(i);
}
}
ll ans = inf;
rep(i,1,n+1){
bfs(i);
ll cost = 0;
bool f = 0;
rep(i,1,n+1){
if (!vis[i]){
f = 1;
continue;
}
cost += d[i]+1;
vis[i] = 0;
}
if (!f) ans = min(ans,cost);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
444 KB |
Output is correct |
12 |
Correct |
4 ms |
460 KB |
Output is correct |
13 |
Correct |
3 ms |
584 KB |
Output is correct |
14 |
Correct |
155 ms |
588 KB |
Output is correct |
15 |
Correct |
19 ms |
604 KB |
Output is correct |
16 |
Correct |
498 ms |
664 KB |
Output is correct |
17 |
Correct |
665 ms |
680 KB |
Output is correct |
18 |
Correct |
666 ms |
676 KB |
Output is correct |