23862023-01-12 10:45:36rennTom és Jerry 1 (80)cpp11Time limit exceeded 64/80575ms17592 KiB
#include <bits/stdc++.h>
using namespace std;
//http://tamop412.elte.hu/tananyagok/algoritmusok/lecke24_lap1.html

void tbejar(vector<int> graf[], int eleres[], int size, int pos)
{
    queue<int> pospool;
    bool volt[size];
    pospool.push(pos);
    volt[pos] = true;
    int k;
    while(!pospool.empty())
    {
        k = pospool.front();
        pospool.pop();
        for(int i : graf[k])
        {
            if(eleres[i] > eleres[k]+1)
            {
                eleres[i] = eleres[k]+1;
                pospool.push(i);
            }
        }
    }
}

bool jbejar(vector<int> graf[], int jeleres[], int teleres[],
            int size, int pos, int cel)
{
    if(cel == pos)
        return true;
    if(teleres[pos] == 0)
        return false;
        
    queue<int> pospool;
    fill(jeleres, jeleres+size, INT_MAX);
    jeleres[pos] = 0;
    pospool.push(pos);
    int k;
    while(!pospool.empty())
    {
        k = pospool.front();
        pospool.pop();
        for(int i : graf[k])
        {
            if(jeleres[i] > jeleres[k]+1)
            {
                if(jeleres[k]+1 < teleres[i])
                {
                    if(i == cel)
                        return true;
                    jeleres[i] = jeleres[k]+1;
                    pospool.push(i);
                }
            }
        }
    }
    return false;
}

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

    int pontok, jaratok, tom, probaszam, haz;
    cin >> pontok >> jaratok >> tom >> probaszam >> haz;

    tom--;
    haz--;

    vector<int> tgraf[pontok];
    vector<int> jgraf[pontok];

    int teleres[pontok];
    int jeleres[pontok];
    fill(teleres, teleres+pontok, INT_MAX);

    teleres[tom] = 0;

    int a, b, c;

    for(int i = 0; i < jaratok; i++)
    {
        cin >> a >> b >> c;
        if(c == 2)
        {
            tgraf[a-1].push_back(b-1);
            tgraf[b-1].push_back(a-1);
        }
        jgraf[a-1].push_back(b-1);
        jgraf[b-1].push_back(a-1);
    }

    tbejar(tgraf, teleres, pontok, tom);

    int proba;

    for(int i = 0; i < probaszam; i++)
    {
        cin >> proba;
        proba--;
        if(jbejar(jgraf, jeleres, teleres, pontok, proba, haz))
        {
            cout << "IGEN\n";
        }
        else cout << "NEM\n";
    }
    
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/03ms1828 KiB
2Accepted0/03ms2260 KiB
3Accepted4/42ms2120 KiB
4Accepted4/42ms2328 KiB
5Accepted4/42ms2572 KiB
6Accepted4/42ms2748 KiB
7Accepted4/43ms2852 KiB
8Accepted4/43ms3208 KiB
9Accepted4/43ms3440 KiB
10Accepted4/43ms3760 KiB
11Accepted4/47ms4284 KiB
12Accepted4/48ms5772 KiB
13Accepted4/413ms6632 KiB
14Accepted4/426ms10048 KiB
15Accepted4/432ms11236 KiB
16Accepted4/441ms17420 KiB
17Accepted4/461ms17592 KiB
18Accepted4/434ms15844 KiB
19Time limit exceeded0/4575ms13312 KiB
20Time limit exceeded0/4561ms13808 KiB
21Time limit exceeded0/4561ms13376 KiB
22Time limit exceeded0/4563ms15904 KiB