Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int long long
int nonempty[1000];
int empty[1000];
vector<int> g[1000];
string type[1000];
int MOD = 1e9 + 7;

void dfs(int x){
	// preprocess
	for(int j = 0 ; j < g[x].size() ; j++){
		dfs(g[x][j]);			
	} 
	if( type[x][0] != 'E' ){
		// main process
		empty[x] = type[x].back() == '?';
		if( type[x][0] == 'R' ){
			for(int i = 1 ; i < (1<<g[x].size()) ; i++){
				int emp = 1;
				int sub = 1;
				for(int j = 0 ; j < g[x].size() ; j++){
					if( i >> j & 1 ){
						emp *= empty[g[x][j]];
						sub *= empty[g[x][j]] + nonempty[g[x][j]];
						sub %= MOD;
					}
				}
				sub -= emp;
				empty[x] |= emp;
				nonempty[x] += sub;
				nonempty[x] %= MOD;
			}
		}else{
			for(int j = 0 ; j < g[x].size() ; j++){
				empty[x] |= empty[g[x][j]];
				nonempty[x] += nonempty[g[x][j]];
				nonempty[x] %= MOD;
			}
		}
	}else{
		empty[x] = type[x].back() == '?';
		int sub = 1;
		int emp = 1;
		for(int j = 0 ; j < g[x].size() ; j++){
			emp *= empty[g[x][j]];
			sub *= (empty[g[x][j]]+nonempty[g[x][j]]);
			sub %= MOD;
			
		}
		nonempty[x] = sub;
		
		
	}
	//cout << x+1 << "  emp:" << empty[x] << " nonemp:" << nonempty[x] << "(" << type[x] << endl;
	
	
	
}
signed main(){
	int N;
	cin >> N;
	for(int i = 0 ; i < N ; i++)
		cin >> type[i];
	for(int i = 0 ; i < N - 1 ; i++){
		int s,t;
		cin >> s >> t;
		--s,--t;
		g[s].push_back(t);
	}
	dfs(0);
	cout << ((nonempty[0] + empty[0])%MOD+MOD)%MOD << endl;
	
	

}

Compiler output:
a.cc: In function 'void dfs(long long int)':
a.cc:17:17: error: reference to 'empty' is ambiguous
   17 |                 empty[x] = type[x].back() == '?';
      |                 ^~~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:302:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(initializer_list<_Tp>)'
  302 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:292:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  292 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:282:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  282 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
a.cc:5:5: note:                 'long long int empty [1000]'
    5 | int empty[1000];
      |     ^~~~~
a.cc:24:56: error: reference to 'empty' is ambiguous
   24 |                                                 emp *= empty[g[x][j]];
      |                                                        ^~~~~
/usr/include/c++/14/bits/range_access.h:302:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(initializer_list<_Tp>)'
  302 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:292:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  292 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:282:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  282 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
a.cc:5:5: note:                 'long long int empty [1000]'
    5 | int empty[1000];
      |     ^~~~~
a.cc:25:56: error: reference to 'empty' is ambiguous
   25 |                                                 sub *= empty[g[x][j]] + nonempty[g[x][j]];
      |                                                        ^~~~~
/usr/include/c++/14/bits/range_access.h:302:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(initializer_list<_Tp>)'
  302 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:292:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  292 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:282:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  282 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
a.cc:5:5: note:                 'long long int empty [1000]'
    5 | int empty[1000];
      |     ^~~~~
a.cc:30:33: error: reference to 'empty' is ambiguous
   30 |                                 empty[x] |= emp;
      |                                 ^~~~~
/usr/include/c++/14/bits/range_access.h:302:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(initializer_list<_Tp>)'
  302 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:292:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  292 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:282:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  282 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
a.cc:5:5: note:                 'long long int empty [1000]'
    5 | int empty[1000];
      |     ^~~~~
a.cc:36:33: error: reference to 'empty' is ambiguous
   36 |                                 empty[x] |= empty[g[x][j]];
      |                                 ^~~~~
/usr/include/c++/14/bits/range_access.h:302:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(initializer_list<_Tp>)'
  302 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:292:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  292 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:282:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  282 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
a.cc:5:5: note:                 'long long int empty [1000]'
    5 | int empty[1000];
      |     ^~~~~
a.cc:36:45: error: reference to 'empty' is ambiguous
   36 |                                 empty[x] |= empty[g[x][j]];
      |                                             ^~~~~
/usr/include/c++/14/bits/range_access.h:302:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(initializer_list<_Tp>)'
  302 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:292:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  292 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:282:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  282 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
a.cc:5:5: note:                 'long long int empty [1000]'
    5 | int empty[1000];
      |     ^~~~~
a.cc:42:17: error: reference to 'empty' is ambiguous
   42 |                 empty[x] = type[x].back() == '?';
      |                 ^~~~~
/usr/include/c++/14/bits/range_access.h:302:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(initializer_list<_Tp>)'
  302 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:292:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  292 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:282:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  282 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
a.cc:5:5: note:                 'long long int empty [1000]'
    5 | int empty[1000];
      |     ^~~~~
a.cc:46:32: error: reference to 'empty' is ambiguous
   46 |                         emp *= empty[g[x][j]];
      |                                ^~~~~
/usr/include/c++/14/bits/range_access.h:302:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(initializer_list<_Tp>)'
  302 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:292:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  292 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:282:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  282 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
a.cc:5:5: note:                 'long long int empty [1000]'
    5 | int empty[1000];
      |     ^~~~~
a.cc:47:33: error: reference to 'empty' is ambiguous
   47 |                         sub *= (empty[g[x][j]]+nonempty[g[x][j]]);
      |                                 ^~~~~
/usr/include/c++/14/bits/range_access.h:302:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(initializer_list<_Tp>)'
  302 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:292:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  292 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:282:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  282 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
a.cc:5:5: note:                 'long long int empty [1000]'
    5 | int empty[1000];
      |     ^~~~~
a.cc: In function 'int main()':
a.cc:72:33: error: reference to 'empty' is ambiguous
   72 |         cout << ((nonempty[0] + empty[0])%MOD+MOD)%MOD << endl;
      |                                 ^~~~~
/usr/include/c++/14/bits/range_access.h:302:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(initializer_list<_Tp>)'
  302 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:292:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  292 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:282:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  282 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
a.cc:5:5: note:                 'long long int empty [1000]'
    5 | int empty[1000];
      |     ^~~~~