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
#define make_pair mp
#define emplace_back pb
#include <bits/stdc++.h>
using namespace std;
mt19937 mt_rand(time(0));
const int N = 3005, M = 1e6 + 5;
int n, m, a, b;
char s[5];
bool mac[N][N];
int main()
{
	scanf("%d%d%d%d", &n, &m, &a, &b);
	while(m--) {
		int x, y;
		scanf("%d%s%d", &x, s, &y);
		mac[x][y] = 1;
		if(s[1] == '-')	 mac[y][x] = 1;
	}

	for(int i=1;i<=n;i++) mac[i][i] = 1;

	for(int h=0;h<5;h++)
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	for(int k=1;k<=n;k++) if(mac[i][k] && mac[k][j]) mac[i][j] = 1;

	int s = (1<<b);
	int ans = 0;
	for(int i=0;i<s;i++) {
		bool ok = 1;
		for(int j=1;j<=a;j++) {
			bool ok2 = 0;
			for(int k=0;k<b;k++) if(i & (1<<k)) if(mac[j][k+a+1]) ok2 = 1;
			if(!ok2) ok = 0;
		}
		if(ok) ans++;
	}
	printf("%d\n", ans);
	return 0;
}