Submission #520121

#TimeUsernameProblemLanguageResultExecution timeMemory
520121krit3379Bosses (BOI16_bosses)C++17
100 / 100
712 ms708 KiB
#include<bits/stdc++.h>
using namespace std;
#define N 5005

long long cnt,sum,ans=1e18;
vector<int> g[N];
bitset<N> vis;
queue<pair<int,int>> q;

int main(){
    int n,i,k,c,a,cou;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&k);
        while(k--)scanf("%d",&c),g[c].push_back(i);
    }
    for(i=1;i<=n;i++){
        vis=0;
        sum=cnt=0;
        q.push({i,1});
        vis[i]=true;
        while(!q.empty()){
            a=q.front().first;
            cou=q.front().second;
            q.pop();
            cnt++;
            sum+=cou;
            for(auto x:g[a])if(!vis[x])vis[x]=true,q.push({x,cou+1});
        }
        if(cnt==n)ans=min(ans,sum);
    }
    printf("%lld",ans);
    return 0;
}

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
bosses.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%d",&k);
      |         ~~~~~^~~~~~~~~
bosses.cpp:15:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         while(k--)scanf("%d",&c),g[c].push_back(i);
      |                   ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...