17792022-12-03 12:24:39bzsofiaTom és Jerry 1 (80)cpp11Time limit exceeded 64/80569ms16516 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()
{
    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/03ms1720 KiB
2Accepted0/04ms2248 KiB
3Accepted4/42ms2168 KiB
4Accepted4/42ms2412 KiB
5Accepted4/42ms2588 KiB
6Accepted4/42ms2672 KiB
7Accepted4/43ms2864 KiB
8Accepted4/44ms3152 KiB
9Accepted4/44ms3268 KiB
10Accepted4/44ms3504 KiB
11Accepted4/410ms3808 KiB
12Accepted4/416ms5248 KiB
13Accepted4/427ms5896 KiB
14Accepted4/450ms9264 KiB
15Accepted4/475ms9588 KiB
16Accepted4/479ms16516 KiB
17Accepted4/4118ms14588 KiB
18Accepted4/482ms11792 KiB
19Time limit exceeded0/4551ms8536 KiB
20Time limit exceeded0/4558ms8716 KiB
21Time limit exceeded0/4569ms7148 KiB
22Time limit exceeded0/4546ms8620 KiB