Pagini recente » Cod sursa (job #412162) | Cod sursa (job #1158264) | Cod sursa (job #2458506) | Cod sursa (job #2721922) | Cod sursa (job #3216598)
#include <fstream>
#include <unordered_map>
#include <vector>
using namespace std;
ifstream f("nfa.in");
ofstream g("nfa.out");
const int N=1e4+5;
int n,x,k;
int nr_fn,fn[1001];
char z;
int m,y,start,query;
unordered_map<int,int>v;
struct pct
{
int x,y;
};
vector<pct>a[N];
bool check(string s,int poz, int nod)
{
if(poz==s.size())
{
for(int i=1;i<=nr_fn;i++)
if(fn[i]==nod)
return true;
return false;
}
bool mx=0;
for(auto vec: a[nod])
if(vec.y==s[poz])
{
mx=max(mx,check(s,poz+1,vec.x));
if(mx==1)
return true;
}
return mx;
}
int main()
{
f>>n>>m>>nr_fn>>start;
for(int i=1;i<=nr_fn;i++)
f>>fn[i];
for(int i=1;i<=m;i++)
{
f>>x>>y>>z;
a[x].push_back({y,z});
}
f>>query;
while(query--)
{
string s;
f>>s;
if(check(s,0,start))
g<<1;
else
g<<0;
g<<'\n';
}
return 0;
}