Pagini recente » Cod sursa (job #125060) | Cod sursa (job #2459851) | Cod sursa (job #1514423) | Cod sursa (job #2507044) | Cod sursa (job #2593578)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("nfa.in");
ofstream fout("nfa.out");
int n, m, k, start, l;
bool ok;
bool stop[301];
vector<pair<int, char>>G[301];
char str[151];
void DFS(int nod, int idx)
{
if(ok) return;
if(idx == l + 1)
{
if(stop[nod])
{
ok = 1;
return;
}
}
for(auto it: G[nod])
{
if(it.second == str[idx])
{
DFS(it.first, idx + 1);
}
}
}
int main()
{
fin >> n >> m >> k;
fin >> start;
for(int i = 1; i <= k; ++i)
{
int x;
fin >> x;
stop[x] = 1;
}
for(int i = 1; i <= m; ++i)
{
int x, y;
char ch;
fin >> x >> y >> ch;
G[x].push_back(make_pair(y, ch));
}
int Q;
fin >> Q;
while(Q--)
{
fin >> (str + 1);
l = strlen(str + 1);
ok = 0;
DFS(start, 1);
fout << ok << "\n";
}
return 0;
}