Submission #83072

# Submission time Handle Problem Language Result Execution time Memory
83072 2018-11-04T19:56:20 Z memetkagan44 Bosses (BOI16_bosses) C++11
0 / 100
2 ms 636 KB
#include<bits/stdc++.h>
using namespace std;
long long res;
vector<int> ogul[5005],ogul2[5005];
bool used[5005];
int n,a,b;
long long dfs(int k){
    long long ans=0;
    for(int i=0;i<ogul2[k].size();i++)
        ans+=dfs(ogul2[k][i]);
    res+=ans+1;
    return ans+1;
}
void build(int k){
    queue<int> q;
    q.push(k);
    used[k]=1;
    while(!q.empty()){
        vector<int> temp;
        int x=q.front();
        q.pop();
        for(int i=0;i<ogul[x].size();i++)
            if(!used[ogul[x][i]]){
                q.push(ogul[x][i]);
                temp.push_back(ogul[x][i]);
                used[ogul[x][i]]=1;
            }
        swap(ogul2[x],temp);
    }
    dfs(k);
    for(int i=1;i<=n;i++)
        if(!used[i]){
            memset(used,0,sizeof(used));
            res=0;
            build(i);
        }
    printf("%lld\n",res);
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a);
        for(int j=1;j<=a;j++){
            scanf("%d",&b);
            ogul[b].push_back(i);
        }
    }
    int k=1;
    while(ogul[k].empty())
        k++;
    build(k);
    return 0;
}

Compilation message

bosses.cpp: In function 'long long int dfs(int)':
bosses.cpp:9:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<ogul2[k].size();i++)
                 ~^~~~~~~~~~~~~~~~
bosses.cpp: In function 'void build(int)':
bosses.cpp:22:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<ogul[x].size();i++)
                     ~^~~~~~~~~~~~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
bosses.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a);
         ~~~~~^~~~~~~~~
bosses.cpp:44:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&b);
             ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 636 KB Output isn't correct
3 Halted 0 ms 0 KB -