Submission #74901

#TimeUsernameProblemLanguageResultExecution timeMemory
74901VardanyanBosses (BOI16_bosses)C++14
100 / 100
635 ms1240 KiB
//#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
const int N = 5001;
vector<int> g[N];
int n;
long long ans = 10000000000000005;
int mark[N];
int main(){
    scanf("%d",&n);
    for(int i = 1;i<=n;i++){
        int k;
        scanf("%d",&k);
        for(int j = 1;j<=k;j++){
            int x;
            scanf("%d",&x);
            g[x].push_back(i);
        }
    }
    for(int i = 1;i<=n;i++){
        long long val = 0;
        memset(mark,0,sizeof(mark));
        mark[i] = 1;
        queue<int> q;
        q.push(i);
        int cnt = 0;
        while(!q.empty()){
            int v = q.front();
            q.pop();
            cnt++;
            val+=mark[v];
            if(val>=ans) break;
            for(int j = 0;j<g[v].size();j++){
                int to = g[v][j];
                if(mark[to]) continue;
                mark[to] = mark[v]+1;
                q.push(to);
            }
        }
        if(cnt == n)
        ans = min(ans,val);
    }
    printf("%lld\n",ans);
    return 0;
}

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:33:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j = 0;j<g[v].size();j++){
                           ~^~~~~~~~~~~~
bosses.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
bosses.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&k);
         ~~~~~^~~~~~~~~
bosses.cpp:16:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x);
             ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...