17812022-12-03 12:49:35bzsofiaTom és Jerry 1 (80)cpp11Time limit exceeded 64/80574ms20636 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> eger(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);
        }

        eger[a].sz.push_back(b);
        eger[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;

        vector <adat> jerry(n+1);

        jerry[jkezd].tav=0;
        jerry[jkezd].lat=1;
        s.push(jkezd);
        while (!s.empty())
        {
            akt=s.front();
            s.pop();
            for (auto &e:eger[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/03ms1696 KiB
2Accepted0/03ms2384 KiB
3Accepted4/42ms2132 KiB
4Accepted4/42ms2212 KiB
5Accepted4/42ms2352 KiB
6Accepted4/42ms2564 KiB
7Accepted4/43ms2960 KiB
8Accepted4/43ms3200 KiB
9Accepted4/43ms3076 KiB
10Accepted4/44ms3356 KiB
11Accepted4/47ms4080 KiB
12Accepted4/410ms6240 KiB
13Accepted4/417ms7224 KiB
14Accepted4/432ms11200 KiB
15Accepted4/446ms11280 KiB
16Accepted4/454ms20636 KiB
17Accepted4/476ms16968 KiB
18Accepted4/450ms14640 KiB
19Time limit exceeded0/4564ms10280 KiB
20Time limit exceeded0/4574ms10304 KiB
21Time limit exceeded0/4537ms8240 KiB
22Time limit exceeded0/4574ms9992 KiB