-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler_tour.cpp
More file actions
114 lines (94 loc) · 2.13 KB
/
euler_tour.cpp
File metadata and controls
114 lines (94 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include<bits/stdc++.h>
using namespace std;
#define ll long long
class SegmentTree{
public:
vector<int>segTree;
vector<int>lazyTree;
SegmentTree(int nodes){
segTree.resize(4*nodes,0);
lazyTree.resize(4*nodes,0);
}
void build(int ind, int left, int right, vector<int>&values){
if(left==right){
segTree[ind]=values[left];
return ;
}
int mid = left+(right-left)/2;
build(2*ind +1, left,mid,values);
build(2*ind +2, mid+1,right,values);
segTree[ind]=segTree[2*ind +1] + segTree[2*ind +2];
}
void propagate(int ind, int val, int start, int end){
segTree[ind] += (end-start+1)*val;
if(start!=end){
lazyTree[2*ind +1]=val;
lazyTree[2*ind +2]=val;
}
}
void update(int ind, int left, int right,int l, int r, int val){
if(lazyTree[ind]!=0){
propagate(ind,lazyTree[ind],left,right);
lazyTree[ind]=0;
}
if(left>r || right<l){
return 0;
}
if(left>=l && right<=r){
segTree[ind]+=val;
lazyTree[ind]+=val;
return ;
}
update(2*ind +1, left, mid, l,r,val);
update(2*ind +2,mid+1,right,l,r,val);
segTree[ind] = segTree[2*ind +1] + segTree[2*ind +2];
}
};
ll isPrime[1e6];
void euler(vector<vector<int>>&graph, vector<int>&val,int sou, int par, int& timer, vector<int>&startTime, vector<int>&endTime, vector<int>&visitedTime, vector<int>&values ){
timer+=1;
startTime[sou]=timer;
if(!isPrime[sou]){
visitedTime.push_back(startTime[sou]);
values.push_back(val[sou]);
}
for(auto it:graph[sou]){
if(it!=par){
euler(graph,val,it,sou,timer,startTime,endTime,visitedTime,values);
}
}
endTime[sou]=timer;
}
int main(){
ll x;
cin>>x;
vector<vector<int>>graph(x);
for(int i=0;i<x-1;i++){
ll sou,des;
cin>>sou>>des;
sou--;
des--;
graph[sou].push_back(des);
graph[des].push_back(sou);
}
vector<int>val(x);
for(int i=0;i<x;i++){
cin>>val[i];
}
vector<int>startTime(x);
vector<int>endTime(x);
vector<int>visitedTime;
vector<int>values;
int timer=0;
memset(isPrime,1,sizeof(isPrime));
isPrime[0]=0;
isPrime[1]=0;
for(int i=2;i<=1e6;i++){
if(isPrime[i]){
for(int j=i;j<=1e6;j+=i){
isPrime[j]=0;
}
}
}
return 0;
}