Submission #42376

# Submission time Handle Problem Language Result Execution time Memory
42376 2018-02-26T15:08:01 Z Hassoony Bosses (BOI16_bosses) C++11
0 / 100
2 ms 716 KB
#include<bits/stdc++.h>
#include<unordered_map>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef long double D;
const ll inf=(1ll<<61);
const ll mod=1e9+7;
const int MX=5009;
int n,k,x,vis[MX],val[MX];
vector<int>v[MX],v1[MX];
ll ans,mn=inf;
void dfs(int x){
    if(v1[x].size()==0){
        val[x]=1;
        ans++;
        return;
    }
    if(vis[x])return;
    vis[x]=1;
    int &ret=val[x];
    for(auto pp:v1[x]){
        if(vis[pp])continue;
        dfs(pp);
        ret+=val[pp];
    }
    ++ret;
    ans+=ret;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&k);
        while(k--){
            scanf("%d",&x);
            v[x].push_back(i);
        }
    }
    for(int i=1;i<=n;i++){
        memset(vis,0,sizeof(vis));
        memset(val,0,sizeof(val));
        for(int j=1;j<=n;j++)v1[i].clear();
        ans=0;
        queue<int>q;
        q.push(i);
        while(!q.empty()){
            int x=q.front();q.pop();
            vis[x]=1;
            for(auto pp:v[x]){
                if(vis[pp])continue;
                v1[x].push_back(pp);
                vis[pp]=1;
                q.push(pp);
            }
        }
        memset(vis,0,sizeof(vis));
        dfs(i);
        mn=min(mn,ans);
    }
    printf("%lld\n",mn);
}

Compilation message

bosses.cpp: In function 'int main()':
bosses.cpp:32:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
bosses.cpp:34:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&k);
                       ^
bosses.cpp:36:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x);
                           ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Incorrect 2 ms 716 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Incorrect 2 ms 716 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Incorrect 2 ms 716 KB Output isn't correct
3 Halted 0 ms 0 KB -