Submission #68914

# Submission time Handle Problem Language Result Execution time Memory
68914 2018-08-19T08:45:19 Z Vahan Bosses (BOI16_bosses) C++17
0 / 100
3 ms 868 KB
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
vector<int> g[20000];
int n,pp,u[100000],pat=-1,t;
int dfs(int v,int p,int h)
{
    int x=1;
    for(int i=0;i<g[v].size();i++)
    {
        int to=g[v][i];
        if(u[to]==0)
        {
            u[to]=h;
            t++;
        }
    }
    for(int i=0;i<g[v].size();i++)
    {
        int to=g[v][i];
        if(u[to]==h)
            x+=dfs(to,v,h+1);
    }
    pp+=x;
    return x;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int a;
        scanf("%d",&a);
        for(int j=1;j<=a;j++)
        {
            int b;
            scanf("%d",&b);
            if(i!=b)
                g[b].push_back(i);
        }
    }
    for(int i=1;i<=n;i++)
    {
        pp=0;
        u[i]=1;
        t=1;
        dfs(i,-1,2);
        if(t==n && (pp<pat || pat==-1))
            pat=pp;
        for(int j=1;j<=n;j++)
            u[j]=0;
    }
    cout<<pat<<endl;
    return 0;
}

Compilation message

bosses.cpp: In function 'int dfs(int, int, int)':
bosses.cpp:10:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<g[v].size();i++)
                 ~^~~~~~~~~~~~
bosses.cpp:19:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<g[v].size();i++)
                 ~^~~~~~~~~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a);
         ~~~~~^~~~~~~~~
bosses.cpp:38: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 3 ms 760 KB Output is correct
2 Incorrect 3 ms 868 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Incorrect 3 ms 868 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Incorrect 3 ms 868 KB Output isn't correct
3 Halted 0 ms 0 KB -