184952025-10-24 12:53:47KristófTom és Jerry 1 (80)cpp17Wrong answer 60/80600ms5796 KiB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

vector<int> BFS(vector<vector<int>> &graph,int v)
{
vector<bool> visit(graph.size()+1,false);
vector<int> layer(graph.size()+1,-1);
queue<int> bfs;
layer[v]=0;
visit[v]=true;
bfs.push(v);
//int layercnt=0;
while(bfs.size()!=0)
    {
    //cout<<graph[v].size()<<endl;
    v=bfs.front();
    //layercnt++;
    visit[v]=true;
    for(auto x : graph[v])
        {
        //cout<<v<<" "<<x<<" "<<layercnt<<endl;
        if(!visit[x])
            {
            bfs.push(x);
            layer[x]=layer[v]+1;
            visit[x]=true;
            }
        }
    bfs.pop();
    }



return layer;
}

void solve(vector<int> &tom,vector<vector<int>> &graph,int s,vector<bool> &visit,bool &p,int &e)
{
//visit[s]=true;
vector<int> jerry(graph.size());
queue<int> bfs;
jerry[s]=0;
bfs.push(s);
while(!bfs.empty())
    {

    int v=bfs.front();bfs.pop();
    visit[v]=true;
    for(int u : graph[v])
        {
        jerry[u]=jerry[v]+1;
        if(tom[u]!=-1)
            {
            if(jerry[u]>=tom[u])
                {
                continue;
                }
            }
        if(u==e)
            {
            p=true;
            return;
            }
        if(!visit[u])
            bfs.push(u);
        visit[u]=true;
        }
    }
}




int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie();
    int n,m,t,jt,e;
    cin>>n>>m>>t>>jt>>e;
    vector<vector<int>>graphj(n+1);
    vector<vector<int>>grapht(n+1);
    int x,y,d;
    for(int i=0;i<m;i++)
        {
        cin>>x>>y>>d;
        graphj[x].push_back(y);
        graphj[y].push_back(x);
        if(d==2)
            {
            //cout<<x<<" "<<y<<endl;
            grapht[x].push_back(y);
            grapht[y].push_back(x);
            }
        }

    vector<int> ans=BFS(grapht,t);
    while(jt--)
        {
        cin>>x;
        //vector<int> jerry=BFS(graphj,x);
        vector<bool> visit(n+1,false);
        bool p=false;
        solve(ans,graphj,x,visit,p,e);
        if(p==false)
            {
            cout<<"NEM"<<"\n";
            }
        else cout<<"IGEN"<<"\n";
        }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base60/80
1Accepted0/01ms512 KiB
2Accepted0/02ms316 KiB
3Accepted4/41ms316 KiB
4Accepted4/41ms316 KiB
5Accepted4/41ms316 KiB
6Wrong answer0/41ms316 KiB
7Accepted4/41ms316 KiB
8Accepted4/42ms316 KiB
9Accepted4/42ms508 KiB
10Accepted4/42ms628 KiB
11Accepted4/46ms820 KiB
12Accepted4/48ms1412 KiB
13Accepted4/413ms1764 KiB
14Accepted4/426ms3068 KiB
15Accepted4/432ms3024 KiB
16Accepted4/448ms5796 KiB
17Accepted4/464ms5172 KiB
18Accepted4/435ms3972 KiB
19Time limit exceeded0/4600ms4916 KiB
20Time limit exceeded0/4600ms5004 KiB
21Time limit exceeded0/4578ms3736 KiB
22Time limit exceeded0/4600ms5228 KiB