UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214850#2642. colorLin_ziluo4078ms3728kbC++11572b2024-11-22 19:16:532024-11-22 23:12:11

answer

#include <bits/stdc++.h>
using namespace std;
char clr[100010],t;
vector<int> g[100010];
bool flag,vis[100010];
void dfs(int u,int fa){
	if (clr[u] == t)
		vis[u] = true;
	vis[u] |= vis[fa];
	for (int v : g[u]){
		if (v == fa)
			continue;
		dfs(v,u);
	}
}
int main(){
	int n,m;
	cin >> n >> m >> clr + 1;
	while (--n){
		int x,y;
		cin >> x >> y;
		g[x].emplace_back(y);
		g[y].emplace_back(x);
	}
	while (m--){
		int x,y;
		cin >> x >> y >> t;
		dfs(x,0);
		cout << vis[y];
		flag = false;
		memset(vis,false,sizeof vis);
	}
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 21ms
memory: 3724kb

input:

920 900
HHHHHHHHHHHHHHHHHHHHHHHHHGHHHHHHHHHHHHGHHHHHHHHHHHHHHHHHHHHHHHGHHGHHHHHHHGGHGHHHGHHGHGHHHHHH...

output:

0010100111100111101010001000010101100010001110110110001101100101111000101111100001111001110100001111...

result:

ok single line: '001010011110011110101000100001...1010100111010011101110111010101'

Test #2:

score: 10
Accepted
time: 17ms
memory: 3724kb

input:

927 949
HHHHGHGGGHHHHGHGHHHHHGHGGHGGGHHHGGHHHHHHGGGGGGHHHGGHHHHGHHHHGGGHHHGHGHHHHGGGGHHGHHGGHGHGGGGG...

output:

1111000011110111101101100110110011110101011000110111111111101110110011111011111110110011101010111111...

result:

ok single line: '111100001111011110110110011011...0011001011010111111011111001110'

Test #3:

score: 10
Accepted
time: 21ms
memory: 3724kb

input:

934 998
HHHHGHHHGHHGGGHGGHGHGHHHGHHGHGGGHHHHHGHHGGHHHHHHGHHHGGHHHHHGGHHHGHHHHHHHGHHGHGHGGHHGHGHHHGGH...

output:

1101010111111010110101011111110111111101101100011111001101110111111111011111101001111011001010101111...

result:

ok single line: '110101011111101011010101111111...1011101110011100101111100101110'

Test #4:

score: 10
Accepted
time: 19ms
memory: 3728kb

input:

941 947
HHHHHHHHHHHHHHHGHHHGHHHGHHHHGHHHGHHHHHHHHGHHHHHHHHHGHHHHHGHHHHHGHHGHHHHGHGGHHGHHHHHHHHHHGGHH...

output:

1111111011010110001101010101110100110001000101100101111101110001111111111110111011010101001111101111...

result:

ok single line: '111111101101011000110101010111...0101100011110110011000000000011'

Test #5:

score: 0
Time Limit Exceeded

input:

92189 98896
HHHHHHHHHGHHHHGGGHGHHHHHHGHHHHHGHHHHHHHHHGHGHHHGHHHHHHGGHHHGHGGHHHHHHHHHGHHHHHHGHGHGHHHG...

output:

1110111111111111111111111111111111111011110111111111111111110111111101111111111111111111111111101111...

result:


Test #6:

score: 0
Time Limit Exceeded

input:

95803 95747
HHHHHHHHHHHHHGHHHHHHHHHHHHHHHHHHGHHGHGHHHHGHGHHHHHHGGHHHHHHHHHHHHGHHHGHHHHHHHHHGHGGHHHHH...

output:

1011011101111111111111111101111111111011101101111110111111101111111011110111111101111111001100101111...

result:


Test #7:

score: 0
Time Limit Exceeded

input:

92610 90996
HHGGGHHGHGGGHGHGHGGGGGGHGGGHGGHGHGHGGHHHHHGHGGHGHGGGGHGGGHGGHHGHHHGGHGHGGHGGGHGGGGGGGGGG...

output:

1111111111111111111011111111111111111110111111111111100111111111011111111111101101111111111111011111...

result:


Test #8:

score: 0
Time Limit Exceeded

input:

96224 91494
HHHHHHHHGGHHGHHHHHHHHHHHHHGHHHGHHHHHHHHHHHHHHHHHGGHHHHHHGHHHHHHHHHHHHHHHHHGHGGGHGHGHHHHH...

output:

1111010110111100111111111111011011010101011111011101111011111011111011111111111111111111111011111101...

result:


Test #9:

score: 0
Time Limit Exceeded

input:

93031 96743
HHHHHHHHHGHHHHHHHHHHHHHHHHHGGHHHHGHHHGHHHHHHHHHGHHHHHHHHHHHHHHGGHHHHHGGHGHHHGHHHGHHHHHHG...

output:

0100011111101111011111110111001111101111110101110110111111111111111101111110110001011110011111011111...

result:


Test #10:

score: 0
Time Limit Exceeded

input:

96645 93594
HHHHHHHHHGHGHHHHHHHGHHHHGGGHHHHHHHHHHHHHHHHHHGHHHHHGHGHHHHHGHGHHHHHGHHHHGHHHHGGHHGHHHHGH...

output:

0101000110111110011111111111110111101011011101111110111111011011111111111110111110101111111111111111...

result: