Submission #533526

# Submission time Handle Problem Language Result Execution time Memory
533526 2022-03-06T08:56:29 Z devariaota Bosses (BOI16_bosses) C++17
100 / 100
779 ms 764 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
const ll MOD=1e9+7;
using namespace std;
ll N,M;
bool visited[5005];
vector <ll> adj[5005];
int main(){
  cin>>N;
  for(int i=1;i<=N;i++){
    cin>>M;
    for(int j=1;j<=M;j++){
      ll temp;
      cin>>temp;
      adj[temp].push_back(i);
    }
  }
  ll minn=1e18;
  for(int i=1;i<=N;i++){
    memset(visited,false,sizeof(visited));
    queue <pair<ll,ll> > que;
    que.push({i,1});
    visited[i]=true;
    ll catat=1;
    ll sum=1;
    while(!que.empty()){
      ll x=que.front().fi;
      ll val=que.front().se;
      que.pop();
      for(auto j:adj[x]){
        if(!visited[j]){
          visited[j]=true;
          catat++;
          sum+=val+1;
          que.push({j,val+1});
        }
      }
    }
    if(catat==N){
      minn=min(minn,sum);
    }
  }
  cout<<minn<<endl;
}
# 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 312 KB Output is correct
4 Correct 1 ms 412 KB Output is correct
5 Correct 1 ms 412 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 312 KB Output is correct
4 Correct 1 ms 412 KB Output is correct
5 Correct 1 ms 412 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 412 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 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 312 KB Output is correct
4 Correct 1 ms 412 KB Output is correct
5 Correct 1 ms 412 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 412 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 5 ms 460 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
14 Correct 178 ms 496 KB Output is correct
15 Correct 6 ms 588 KB Output is correct
16 Correct 608 ms 764 KB Output is correct
17 Correct 742 ms 624 KB Output is correct
18 Correct 779 ms 672 KB Output is correct