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
#include<bits/stdc++.h>
using namespace std;
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<int, int>;

vector<vector<int>> adj;

void dfs(int v, vector<bool> &vis) {
	vis[v] = true;
	for(int u : adj[v]) {
		if(!vis[u])
			dfs(u, vis);
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, m, a, b;
	cin >> n >> m >> a >> b;

	adj.resize(n);
	REP(i, m) {
		int u, v;
		string str;
		cin >> u >> str >> v;
		if(str[0] == '-') adj[u - 1].emplace_back(v - 1);
		if(str[1] == '-') adj[v - 1].emplace_back(u - 1);
	}

	vector<int> reach(a);
	REP(i, a) {
		vector<bool> vis(n);
		dfs(i, vis);
		FOR(j, a, n - 1) 
			reach[i] += vis[j] * (1 << (j - a));
		debug(i, vis, reach[i]);
	}

	int ans = 0;
	REP(mask, 1 << b) {
		bool ok = true;
		REP(i, a) ok = ok && reach[i] & mask;
		debug(ok);
		ans += ok;
	}

	cout << ans << "\n";
}