Submission #535919

# Submission time Handle Problem Language Result Execution time Memory
535919 2022-03-11T20:23:15 Z groshi Cat in a tree (BOI17_catinatree) C++17
0 / 100
0 ms 212 KB
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
struct wi{
    vector<int> Q;
    int gdzie=0;
}*w;
int moge[1000000];
bool utnij[1000000];
void dfs(int x,int ile)
{
    moge[x]=ile;
    if(ile==1)
        return;
    for(int i=0;i<w[x].Q.size();i++)
    {
        int pom=w[x].Q[i];
        if(utnij[w[pom].gdzie]==0 && moge[pom]<ile-1)
            dfs(pom,ile-1);
    }
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int n,d,x;
    cin>>n>>d;
    w=new wi[n+3];
    vector<pair<int,int> > mam;
    mam.push_back({0,0});
    for(int i=1;i<n;i++)
    {
        cin>>x;
        w[i].gdzie=w[x].gdzie+1;
        w[i].Q.push_back(x);
        w[x].Q.push_back(i);
        mam.push_back({w[i].gdzie,i});
    }
    sort(mam.begin(),mam.end());
    int wynik=0;
    mam.push_back({-1,-1});
    for(int i=mam.size()-2;i>=0;i--)
    {
        cout<<mam[i].second<<" "<<mam[i].first<<"\n";
        int jestem=mam[i].second;
        if(i>0 && mam[i].first<mam[i+1].first)
            utnij[mam[i+1].first]=1;
        if(moge[jestem]==0)
        {
            dfs(jestem,d);
            wynik++;
        }
    }
    cout<<wynik;
    return 0;
}

Compilation message

catinatree.cpp: In function 'void dfs(int, int)':
catinatree.cpp:17:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i=0;i<w[x].Q.size();i++)
      |                 ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -