제출 #375902

#제출 시각아이디문제언어결과실행 시간메모리
375902ntabc05101Cat in a tree (BOI17_catinatree)C++14
100 / 100
110 ms18944 KiB
#include<bits/stdc++.h> const int max_n=200000; int n, d; std::vector<int> adjList[5+max_n]; std::pair<int, int> dfs(int vertex, int parent=-1) { std::vector< std::pair<int, int> > v; for (auto& to: adjList[vertex]) { if (to!=parent) { v.push_back(dfs(to, vertex)); } } if (v.empty()) { return std::make_pair(1, 1); } std::sort(begin(v), end(v), std::greater< std::pair<int, int> >()); int pos=1; while (pos<v.size() and v[pos].first+v[pos-1].first>=d) ++pos; --pos; int ret=pos+1; for (auto& _: v) ret+=_.second-1; if (v.back().first>=d) { ++ret; return std::make_pair(1, ret); } return std::make_pair(v[pos].first+1, ret); } int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cin>>n>>d; for (int i=1, x; i<n; ++i) { std::cin>>x; adjList[x].push_back(i); } std::cout<<dfs(0).second<<"\n"; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

catinatree.cpp: In function 'std::pair<int, int> dfs(int, int)':
catinatree.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         while (pos<v.size() and v[pos].first+v[pos-1].first>=d) ++pos;
      |                ~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...