Submission #1103663

#TimeUsernameProblemLanguageResultExecution timeMemory
1103663Ahmed57Tree (IOI24_tree)C++17
0 / 100
62 ms17316 KiB
#include <bits/stdc++.h> using namespace std; long long cnt = 0; bool nah = 0; int root = -1; int w[200001]; int deg[200001]; vector<int> adj[200001]; vector<int> na,pref; int dfs(int i,int pr){ int c1 = 0; for(auto j:adj[i]){ if(j==pr)continue; int x = dfs(j,i); if(w[i]==0){ na.push_back(x); } c1+=x; } if((adj[i].size()==1&&root!=i)||w[i]==0){ c1 = 1; } return c1; } void init(std::vector<int> P, std::vector<int> W){ if(P.size()==1){ nah = 1; } for(int i = 0;i<P.size();i++){ w[i] = W[i]; int x = P[i]; if(x==-1){ root = x; }else{ adj[i].push_back(x); adj[x].push_back(i); deg[x]++; deg[i]++; } } for(int i = 0;i<P.size();i++){ if(i==root)continue; if(deg[i]==1&&w[i])cnt++; } na.push_back(dfs(root,-1)); sort(na.begin(),na.end()); int xx = 0; for(int i = 0;i<na.size();i++){ xx+=na[i]; pref.push_back(xx); } } long long query(int L, int R){ if(nah)return (w[0]==0?0:L); long long all = cnt*L; int it = lower_bound(na.begin(),na.end(),(R+L-1)/L)-na.begin(); long long f = pref.back()-(it==0?0:pref[it-1]); long long d = pref.size()-it; all+=f*L-d*R; return all; }

Compilation message (stderr)

tree.cpp: In function 'void init(std::vector<int>, std::vector<int>)':
tree.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i = 0;i<P.size();i++){
      |                   ~^~~~~~~~~
tree.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i = 0;i<P.size();i++){
      |                   ~^~~~~~~~~
tree.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i = 0;i<na.size();i++){
      |                   ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...