Submission #521778

# Submission time Handle Problem Language Result Execution time Memory
521778 2022-02-03T05:23:02 Z christinelynn Cat in a tree (BOI17_catinatree) C++17
51 / 100
63 ms 20272 KB
#include <bits/stdc++.h>
using namespace std;
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define Add(x,y) x=(x+y)%mod
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
 
const int N=1e5+99;
 
int n,t,d,ans,a[N],h[N],mark[N],dist[N];
vector<int> v,g[N];
 
bool cmp(int i,int j){
  return h[i]>h[j];
}
void dfs1(int x,int par){
  v.pb(x);
  f(i,0,g[x].size()){
    if(g[x][i]!=par){
      h[g[x][i]]=h[x]+1;
      dfs1(g[x][i],x);
    }
  }
}
void dfs2(int x,int par,int d){
  if(dist[x]<=d) return ;
  dist[x]=d;
  f(i,0,g[x].size()){
    if(g[x][i]!=par){
      dfs2(g[x][i],x,d+1);
    }
  } 
}
 
int main(){
  cin>>n>>d;
  f(i,1,n){
    int x;
    cin>>x;
    g[i].pb(x);
    g[x].pb(i);
  }
  dfs1(1,n);
  fill(dist,dist+N,d);
  sort(v.begin(),v.end(),cmp);
  f(i,0,v.size()){
    int u=v[i];
    if(dist[u]==d){
      ans++;
      dfs2(u,n,0);
    }
  }
  cout<<ans;
}

Compilation message

catinatree.cpp: In function 'void dfs1(int, int)':
catinatree.cpp:7:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   30 |   f(i,0,g[x].size()){
      |     ~~~~~~~~~~~~~~~            
catinatree.cpp:30:3: note: in expansion of macro 'f'
   30 |   f(i,0,g[x].size()){
      |   ^
catinatree.cpp: In function 'void dfs2(int, int, int)':
catinatree.cpp:7:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   40 |   f(i,0,g[x].size()){
      |     ~~~~~~~~~~~~~~~            
catinatree.cpp:40:3: note: in expansion of macro 'f'
   40 |   f(i,0,g[x].size()){
      |   ^
catinatree.cpp: In function 'int main()':
catinatree.cpp:7:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   58 |   f(i,0,v.size()){
      |     ~~~~~~~~~~~~               
catinatree.cpp:58:3: note: in expansion of macro 'f'
   58 |   f(i,0,v.size()){
      |   ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3020 KB Output is correct
2 Correct 2 ms 3036 KB Output is correct
3 Correct 2 ms 3020 KB Output is correct
4 Correct 2 ms 3020 KB Output is correct
5 Correct 2 ms 3020 KB Output is correct
6 Correct 2 ms 3020 KB Output is correct
7 Correct 2 ms 3020 KB Output is correct
8 Correct 2 ms 3020 KB Output is correct
9 Correct 2 ms 3020 KB Output is correct
10 Correct 2 ms 3148 KB Output is correct
11 Correct 2 ms 3020 KB Output is correct
12 Correct 2 ms 3028 KB Output is correct
13 Correct 2 ms 3036 KB Output is correct
14 Correct 2 ms 3020 KB Output is correct
15 Correct 2 ms 3020 KB Output is correct
16 Correct 2 ms 3020 KB Output is correct
17 Correct 2 ms 3020 KB Output is correct
18 Correct 2 ms 3020 KB Output is correct
19 Correct 2 ms 3020 KB Output is correct
20 Correct 2 ms 3036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3020 KB Output is correct
2 Correct 2 ms 3036 KB Output is correct
3 Correct 2 ms 3020 KB Output is correct
4 Correct 2 ms 3020 KB Output is correct
5 Correct 2 ms 3020 KB Output is correct
6 Correct 2 ms 3020 KB Output is correct
7 Correct 2 ms 3020 KB Output is correct
8 Correct 2 ms 3020 KB Output is correct
9 Correct 2 ms 3020 KB Output is correct
10 Correct 2 ms 3148 KB Output is correct
11 Correct 2 ms 3020 KB Output is correct
12 Correct 2 ms 3028 KB Output is correct
13 Correct 2 ms 3036 KB Output is correct
14 Correct 2 ms 3020 KB Output is correct
15 Correct 2 ms 3020 KB Output is correct
16 Correct 2 ms 3020 KB Output is correct
17 Correct 2 ms 3020 KB Output is correct
18 Correct 2 ms 3020 KB Output is correct
19 Correct 2 ms 3020 KB Output is correct
20 Correct 2 ms 3036 KB Output is correct
21 Correct 2 ms 3160 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 2 ms 3020 KB Output is correct
24 Correct 2 ms 3032 KB Output is correct
25 Correct 3 ms 3020 KB Output is correct
26 Correct 2 ms 3028 KB Output is correct
27 Correct 2 ms 3020 KB Output is correct
28 Correct 2 ms 3036 KB Output is correct
29 Correct 2 ms 3020 KB Output is correct
30 Correct 2 ms 3036 KB Output is correct
31 Correct 2 ms 3020 KB Output is correct
32 Correct 2 ms 3020 KB Output is correct
33 Correct 2 ms 3020 KB Output is correct
34 Correct 2 ms 3032 KB Output is correct
35 Correct 3 ms 3148 KB Output is correct
36 Correct 2 ms 3020 KB Output is correct
37 Correct 3 ms 3032 KB Output is correct
38 Correct 2 ms 3020 KB Output is correct
39 Correct 3 ms 3148 KB Output is correct
40 Correct 2 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3020 KB Output is correct
2 Correct 2 ms 3036 KB Output is correct
3 Correct 2 ms 3020 KB Output is correct
4 Correct 2 ms 3020 KB Output is correct
5 Correct 2 ms 3020 KB Output is correct
6 Correct 2 ms 3020 KB Output is correct
7 Correct 2 ms 3020 KB Output is correct
8 Correct 2 ms 3020 KB Output is correct
9 Correct 2 ms 3020 KB Output is correct
10 Correct 2 ms 3148 KB Output is correct
11 Correct 2 ms 3020 KB Output is correct
12 Correct 2 ms 3028 KB Output is correct
13 Correct 2 ms 3036 KB Output is correct
14 Correct 2 ms 3020 KB Output is correct
15 Correct 2 ms 3020 KB Output is correct
16 Correct 2 ms 3020 KB Output is correct
17 Correct 2 ms 3020 KB Output is correct
18 Correct 2 ms 3020 KB Output is correct
19 Correct 2 ms 3020 KB Output is correct
20 Correct 2 ms 3036 KB Output is correct
21 Correct 2 ms 3160 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 2 ms 3020 KB Output is correct
24 Correct 2 ms 3032 KB Output is correct
25 Correct 3 ms 3020 KB Output is correct
26 Correct 2 ms 3028 KB Output is correct
27 Correct 2 ms 3020 KB Output is correct
28 Correct 2 ms 3036 KB Output is correct
29 Correct 2 ms 3020 KB Output is correct
30 Correct 2 ms 3036 KB Output is correct
31 Correct 2 ms 3020 KB Output is correct
32 Correct 2 ms 3020 KB Output is correct
33 Correct 2 ms 3020 KB Output is correct
34 Correct 2 ms 3032 KB Output is correct
35 Correct 3 ms 3148 KB Output is correct
36 Correct 2 ms 3020 KB Output is correct
37 Correct 3 ms 3032 KB Output is correct
38 Correct 2 ms 3020 KB Output is correct
39 Correct 3 ms 3148 KB Output is correct
40 Correct 2 ms 3164 KB Output is correct
41 Runtime error 63 ms 20272 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -