제출 #1028329

#제출 시각아이디문제언어결과실행 시간메모리
1028329hasan2006Cat in a tree (BOI17_catinatree)C++17
100 / 100
74 ms34540 KiB
#include <bits/stdc++.h> using namespace std; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define se second #define fi first #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" const int N = 2e5 + 9 , mod = 1e9 + 7; ll dp[N] , a[N] ,c[N] , d[N] , b[N] , p[N]; vector<int>v[N]; void dfs(int n ,int k){ if(n) d[n] = d[p[n]] + 1; for(auto to : v[n]) dfs(to , k); vector<pair<ll,ll>>vc , vv; vc.pb({d[n] , 1}); for(auto to : v[n]) vc.pb({c[to] , dp[to]}); sort(all(vc)); ll r = vc.size() - 1 , sum = 0; for(auto to : vc) sum += to.se; for(int i = 0; i < vc.size(); i++){ while(r >= 0 && (vc[i].fi - d[n] + vc[r].fi - d[n]) >= k) r--; if((r + 1) < i) break; ll x = sum - (r + 1) + (i <= r); vv.pb({x , vc[i].fi}); } sort(all(vv)); dp[n] = vv.back().fi; c[n] = vv.back().se; } void solve() { ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ; cin>>n>>k; for( i= 1; i < n; i++){ cin>>p[i]; v[p[i]].pb(i); } dfs(0 , k); cout<<dp[0]<<"\n"; } int main(){ TL; /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ int t = 1; // cin>>t; while(t--) { solve(); } } // Author : حسن

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

catinatree.cpp: In function 'void dfs(int, int)':
catinatree.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i = 0; i < vc.size(); i++){
      |                    ~~^~~~~~~~~~~
catinatree.cpp: In function 'void solve()':
catinatree.cpp:55:12: warning: unused variable 'q' [-Wunused-variable]
   55 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |            ^
catinatree.cpp:55:20: warning: unused variable 'j' [-Wunused-variable]
   55 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                    ^
catinatree.cpp:55:23: warning: unused variable 'l' [-Wunused-variable]
   55 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                       ^
catinatree.cpp:55:26: warning: unused variable 'r' [-Wunused-variable]
   55 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                          ^
catinatree.cpp:55:30: warning: unused variable 'x' [-Wunused-variable]
   55 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                              ^
catinatree.cpp:55:34: warning: unused variable 'y' [-Wunused-variable]
   55 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                  ^
catinatree.cpp:55:38: warning: unused variable 's' [-Wunused-variable]
   55 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                      ^
catinatree.cpp:55:46: warning: unused variable 'f' [-Wunused-variable]
   55 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                              ^
catinatree.cpp:55:54: warning: unused variable 'm' [-Wunused-variable]
   55 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                      ^
catinatree.cpp:55:58: warning: unused variable 'mn' [-Wunused-variable]
   55 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                          ^~
catinatree.cpp:55:69: warning: unused variable 'mx' [-Wunused-variable]
   55 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                                     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...