제출 #486332

#제출 시각아이디문제언어결과실행 시간메모리
486332Koosha_mvCat in a tree (BOI17_catinatree)C++14
100 / 100
205 ms21188 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=2e5+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; }

컴파일 시 표준 에러 (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:2: 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:2: 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:2: 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...