-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicpc7402.cpp
More file actions
99 lines (77 loc) · 1.92 KB
/
icpc7402.cpp
File metadata and controls
99 lines (77 loc) · 1.92 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
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
#define LC (idx<<1)
#define RC (idx<<1)+1
const int MAXN = 100100;
struct Edge {
int val, next;
} edge[MAXN];
int edgeHead[MAXN];
int cidx;
bool visited[MAXN];
int color[MAXN];
int [MAXN];
struct TreeNode {
int low, high;
} node[MAXN];
struct SegmentTree {
set<int> color;
} stnode[MAXN << 1];
void dfs(int root) {
node[root].low = ++cidx;
visited[root] = true;
for(int i = edgeHead[root]; i != -1; i = edge[i].next)
if(!visited[edge[i].val])
dfs(edge[i].val);
node[root].high = cidx;
}
void build(int L, int R, int idx) {
if(L == R) {
stnode[idx].color.clear();
stnode[idx].color.insert(color[node[L].high]);
return;
}
int M = (L + R) >> 1;
build(L, M, LC);
build(M+1, R, RC);
stnode[idx].color.clear();
stnode[idx].color.insert(stnode[LC].color.begin(), stnode[LC].color.end());
stnode[idx].color.insert(stnode[RC].color.begin(), stnode[RC].color.end());
}
void pushDown()
void pullUp(int idx, int L, int R) {
stnode[idx].color.clear();
stnode[idx].color.insert(stnode[LC].color.begin(), stnode[LC].color.end());
stnode[idx].color.insert(stnode[RC].color.begin(), stnode[RC].color.end());
}
void update(int L, int R, int idx, int tL, int tR, int value) {
}
void add_edge(int i, int from, int to) {
edge[i].val = to;
edge[i].next = edgeHead[from];
edgeHead[from] = i;
}
int main() {
int T;
int N, M;
scanf("%d", &T);
for(int nt = 1; nt <= T; ++nt) {
memset(edgeHead, -1, sizeof(edgeHead));
memset(visited, false, sizeof(visited));
cidx = 0;
scanf("%d", &N);
int from, to;
for(int i = 1; i < N; ++i) {
scanf("%d%d", &from, &to);
add_edge(i, from, to);
}
for(int i = 1; i <= N; ++i) {
scanf("%d", &color[i]);
}
dfs(1);
build(1, N, 1);
}
return 0;
}