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
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 500010;

using ll = long long int;

vector<int> graf[MAXN];
int n, m, a, b;
ll mask[MAXN];

ll DFS(int v, int prevv) {
    ll ret = (v > a && v <= a + b) ? (1LL << (v - a - 1)) : 0;
    for (int x : graf[v])
        if (x != prevv)
            ret |= DFS(x, v);
    return ret;
}

int main() {
    scanf("%d%d%d%d", &n, &m, &a, &b);
    for (int i = 0; i < m; i++) {
        int a;
        string k;
        int b;
        cin >> a >> k >> b;
        graf[a].push_back(b);
        if (k == "--") graf[b].push_back(a);
    }

    for (int i = 1; i <= a; i++) {
        mask[i - 1] = DFS(i, i);
    }

    ll out = 0;
    ll mod = 1000 * 1000 * 1000 + 7;
    for (ll x = 0; x < (1LL << b); x++) {
        bool git = true;
        for (int i = 0; i < a; i++)
            if (!(mask[i] & x)) {
                git = false;
                break;
            }
        out += git;
    }
    printf("%lld\n", out % mod);
}