제출 #668584

#제출 시각아이디문제언어결과실행 시간메모리
668584ktkeremCat in a tree (BOI17_catinatree)C++17
100 / 100
100 ms27692 KiB
/*#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/ #include<bits/stdc++.h> /**/ //typedef int ll; typedef long long ll; typedef unsigned long long ull; typedef std::string str; //typedef vector<std::vector<ll>> vv; /*typedef __int128 vll; typedef unsigned __int128 uvll;*/ #define llll std::pair<ll , ll> #define pb push_back #define pf push_front #define halo cout << "hello\n" #define fi first #define sec second #define vv(x) std::vector<std::vector<x>> #define all(a) a.begin() , a.end() const ll limit = 1e15+7; const ll ous = 2e5 + 7; const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1}; ll n , m;std::vector<ll> adj[ous]; llll dfs(ll crt , ll prv){ std::vector<ll> v;v.pb(0ll); ll tot = 0; for(auto j:adj[crt]){ if(j != prv){ llll o = dfs(j , crt); tot+=o.fi; v.pb(o.sec); } } std::sort(all(v)); while(v.size() > 1 && v.back() + v[(ll)v.size() - 2] > m){ tot--; v.pop_back(); } if(v[(ll)v.size() -1] == 0){ return {tot+1 , m-1}; } return {tot , v.back() - 1}; } void solve(){ std::cin >> n >> m; for(ll i =1;n>i;i++){ ll x;std::cin >> x; adj[x].pb(i); adj[i].pb(x); } llll ans = dfs(0 , -1); std::cout << ans.fi << "\n"; return;/**/ } signed main(){ std::ios_base::sync_with_stdio(false);std::cin.tie(NULL); ll t=1; //std::cin >> t; ll o = 1; while(t--){ //cout << "Case " << o++ << ":\n"; solve(); } return 0; }/**/

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

catinatree.cpp:5:78: warning: "/*" within comment [-Wcomment]
    5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
      |                                                                               
catinatree.cpp: In function 'int main()':
catinatree.cpp:62:8: warning: unused variable 'o' [-Wunused-variable]
   62 |     ll o = 1;
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...