Pagini recente » Cod sursa (job #867785) | Cod sursa (job #1438899) | Cod sursa (job #2850175) | Cod sursa (job #2494626) | Cod sursa (job #2583234)
#include <bits/stdc++.h>
using namespace std;
using Bitset = bitset<512>;
int main() {
ifstream cin("nfa.in");
ofstream cout("nfa.out");
int n, m, k; cin >> n >> m >> k;
vector<vector<Bitset>> graph(n, vector<Bitset>(26));
Bitset fini;
int x; cin >> x; --x;
while (k--) {
int x; cin >> x; --x;
fini[x] = true;
}
for (int i = 0; i < m; ++i) {
int a, b; char c; cin >> a >> b >> c;
--a; --b; c -= 'a';
graph[a][c][b] = true;
}
int q; cin >> q;
while (q--) {
string s; cin >> s;
Bitset now; now[x] = true;
for (auto c : s) {
Bitset nxt;
for (int i = 0; i < n; ++i)
if (now[i]) nxt |= graph[i][c - 'a'];
swap(now, nxt);
}
now &= fini;
bool ok = false;
for (int i = 0; i < n; ++i)
if (now[i]) ok = true;
cout << ok << '\n';
}
return 0;
}