Submission #521778

#TimeUsernameProblemLanguageResultExecution timeMemory
521778christinelynnCat in a tree (BOI17_catinatree)C++17
51 / 100
63 ms20272 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...