Submission #1103663

# Submission time Handle Problem Language Result Execution time Memory
1103663 2024-10-21T14:00:42 Z Ahmed57 Tree (IOI24_tree) C++17
0 / 100
62 ms 17316 KB
#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

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 time Memory Grader output
1 Incorrect 2 ms 4944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 16068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5200 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5200 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 17316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 17316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 16068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4944 KB Output isn't correct
2 Halted 0 ms 0 KB -