제출 #871042

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
8710422023-11-09 18:39:52Theo830Fountain (eJOI20_fountain)C++17
100 / 100
417 ms34792 KiB
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
vector<vector<int> >adj;
const int N = 1e5 + 5;
const int K = 18; /// K = log2N
int d[N],c[N];
int lift[N][K];
long long sum[N][K];
void dfs(int idx,int p){
lift[idx][0] = p;
sum[idx][0] = c[idx];
for(int j = 1;j < K;j++){
lift[idx][j] = lift[lift[idx][j-1]][j-1];
sum[idx][j] = sum[idx][j-1] + sum[lift[idx][j-1]][j-1];
}
for(auto x:adj[idx]){
if(x != p){
dfs(x,idx);
}
}
}
int main(void){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,q;
cin>>n>>q;
adj.assign(n+5,vector<int>());
for(int i = 1;i <= n;i++){
cin>>d[i]>>c[i];
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...