제출 #932986

#제출 시각아이디문제언어결과실행 시간메모리
932986LucaIlieCat in a tree (BOI17_catinatree)C++17
100 / 100
77 ms26448 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2e5; int n, d; int cats[MAX_N], dist[MAX_N]; vector<int> adj[MAX_N]; struct cd { int cats, dist; }; void dfs( int u ) { vector<cd> o; cats[u] = 0; dist[u] = n; o.push_back( { 1, 0 } ); for ( int v: adj[u] ) { dfs( v ); o.push_back( { cats[v], dist[v] + 1 } ); } sort( o.begin(), o.end(), []( cd a, cd b ) { return a.dist < b.dist; } ); int i; for ( i = 0; i < o.size() - 1; i++ ) { if ( o[i].dist + o[i + 1].dist < d ) cats[u] += o[i].cats - 1; else break; } for ( ; i < o.size(); i++ ) { cats[u] += o[i].cats; dist[u] = min( dist[u], o[i].dist ); } } int main() { cin >> n >> d; for ( int v = 1; v < n; v++ ) { int p; cin >> p; adj[p].push_back( v ); } dfs( 0 ); cout << cats[0]; return 0; }

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

catinatree.cpp: In function 'void dfs(int)':
catinatree.cpp:30:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<cd>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for ( i = 0; i < o.size() - 1; i++ ) {
      |                  ~~^~~~~~~~~~~~~~
catinatree.cpp:36:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<cd>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for ( ; i < o.size(); i++ ) {
      |             ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...