Submission #541246

# Submission time Handle Problem Language Result Execution time Memory
541246 2022-03-22T20:19:41 Z Ahmad_Hasan Birokracija (COCI18_birokracija) C++17
60 / 100
1000 ms 14536 KB
#include <bits/stdc++.h>

using namespace std;

vector<vector<int>>adj  ;
int n;
vector<int>can;
vector<int>ans;
int o=0;
int dfs(int m=0,int p=-1){
    /**
    if(vis[m]==1||can[m]==1){
        return 0;
    }*/

    /**if(adj[m].size()==1&&m!=0){///leaf node
        can[m]=1;
        return 1;

    }*/


    int mn=1e6;
    for(int i=0;i<adj[m].size();i++){
        int nd=adj[m][i];
        if(nd!=p&&!can[nd]){
            mn=nd;
            break;
        }
    }

    if(mn==1e6){
        can[m]=1;
        ans[m]+=1;
        return 1;

    }

    int ret=dfs(mn,m);
    ret++;
    ans[m]+=ret;
    return ret;
}
int main()
{


    cin>>n;

    adj=vector<vector<int> >(n);
    can=ans=vector<int>(n);

    for(int i=2;i<=n;i++){
        int u;
        cin>>u;
        adj[u-1].push_back(i-1);
        adj[i-1].push_back(u-1);
    }
    for(int i=0;i<n;i++){
        dfs();
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<' ';
    }
    cout<<'\n';
    return 0;
}

Compilation message

birokracija.cpp: In function 'int dfs(int, int)':
birokracija.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=0;i<adj[m].size();i++){
      |                 ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1620 KB Output is correct
2 Correct 618 ms 2020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 5328 KB Output is correct
2 Execution timed out 1089 ms 5232 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 164 ms 14536 KB Output is correct
2 Execution timed out 1089 ms 14400 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 160 ms 14524 KB Output is correct
2 Execution timed out 1087 ms 14280 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 161 ms 14284 KB Output is correct
2 Execution timed out 1080 ms 14100 KB Time limit exceeded
3 Halted 0 ms 0 KB -