17802022-12-03 12:26:18bzsofiaTom és Jerry 1 (80)cpp11Time limit exceeded 64/80574ms16612 KiB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct adat
{
    int tav=-1;
    vector <int> sz;
    bool lat;
};

queue <int> s;
int i, n, m, tkezd, jkezd, cel, t, a, b, c, akt, j;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>m>>tkezd>>t>>cel;

    vector <adat> jerry(n+1), tom(n+1);

    for (i=1; i<=m; ++i)
    {
        cin>>a>>b>>c;

        if (c==2)
        {
            tom[a].sz.push_back(b);
            tom[b].sz.push_back(a);
        }

        jerry[a].sz.push_back(b);
        jerry[b].sz.push_back(a);
    }

    tom[tkezd].tav=0;
    tom[tkezd].lat=1;
    s.push(tkezd);
    while (!s.empty())
    {
        akt=s.front();
        s.pop();
        for (auto &e:tom[akt].sz)
        {
            if (!tom[e].lat)
            {
                tom[e].lat=1;
                tom[e].tav=tom[akt].tav+1;
                s.push(e);
            }
        }
    }

    for (i=1; i<=t; ++i)
    {
        cin>>jkezd;

        for (j=1; j<=n; ++j)
        {
            jerry[j].tav=-1;
            jerry[j].lat=0;
        }

        jerry[jkezd].tav=0;
        jerry[jkezd].lat=1;
        s.push(jkezd);
        while (!s.empty())
        {
            akt=s.front();
            s.pop();
            for (auto &e:jerry[akt].sz)
            {
                if (!jerry[e].lat && (jerry[akt].tav+1<tom[e].tav || tom[e].tav==-1))
                {
                    jerry[e].lat=1;
                    jerry[e].tav=jerry[akt].tav+1;
                    s.push(e);
                }
            }
        }

        if (jerry[cel].tav>-1) cout<<"IGEN\n";
        else cout<<"NEM\n";
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/03ms1936 KiB
2Accepted0/03ms2504 KiB
3Accepted4/42ms2148 KiB
4Accepted4/42ms2340 KiB
5Accepted4/42ms2556 KiB
6Accepted4/42ms2768 KiB
7Accepted4/43ms3160 KiB
8Accepted4/43ms3428 KiB
9Accepted4/43ms3476 KiB
10Accepted4/44ms3840 KiB
11Accepted4/47ms4512 KiB
12Accepted4/49ms6036 KiB
13Accepted4/417ms6552 KiB
14Accepted4/428ms9676 KiB
15Accepted4/443ms10204 KiB
16Accepted4/452ms16612 KiB
17Accepted4/474ms14788 KiB
18Accepted4/445ms12652 KiB
19Time limit exceeded0/4564ms8840 KiB
20Time limit exceeded0/4569ms9008 KiB
21Time limit exceeded0/4574ms7428 KiB
22Time limit exceeded0/4555ms8888 KiB