现有一棵树,有以下操作:
- 节点x及其所有子孙颜色都变更为k。
- 要求你回答节点x的颜色。
初始所有点都没有染色。
Input
第一行一个整数T(T <= 10),表示样例组数。
对于每个测试样例:
第一行一个整数n(n <= 5e4),表示树的节点个数。
接下来n行,每行两个整数u, v(1 <= u, v <= n),表示树中u的父节点是v。
接下来一行一个整数q(q <= 5e4),表示询问数。
接下来q行:
若为染色操作则输入“T x k”,若为查询操作则输入“C x”,(1 <= x <= n, 0 <= y <= 1e9)。
Output
每个测试样例首先输出一行"Case #x:",其中x为当前样例编号。
对于每个询问操作输出一个整数,表示当前节点的颜色,若还未染色则输出-1。
Sample Input
1
5
4 3
3 2
1 3
5 2
5
C 3
T 2 1
C 3
T 3 2
C 3
Sample Output
Case #1:
-1
1
2
对T的操作是把当前节点的子节点都染一遍色,其实就是对标记下传的操作,每一个节点的标记都会被改变。
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#define ls (p<<1)
#define rs (p<<1|1)
#define mid ((l+r)>>1)
//#include<bits/stdc++.h>
using namespace std;
const int mod=100000073;
const int maxn=1e5+5;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int minn=0xc0c0c0c0;
string s;
bool vis[maxn];
int m,n,o,t,x