24372023-01-13 10:01:22rennTom és Jerry 3cpp11Wrong answer 18/50172ms8656 KiB
#include    <bits/stdc++.h>
using namespace std;

typedef vector<vector<int>> gr;
typedef pair<int, int> pii;

inline int bfs(gr &graf, int kezdo, vector<int> &tavok)
{
    queue<int> next;
    next.push(kezdo);

    int i;
    while(!next.empty())
    {
        i = next.front();
        next.pop();

        for(auto &x : graf[i])
        {
            if(tavok[x] > -1) continue;

            next.push(x);
            tavok[x] = tavok[i]+1;
        }
    }

    return i;
}

inline int bfsm(gr &graf, int kezdo)
{
    queue<int> next;
    next.push(kezdo);
    vector<int> tavok(graf.size(), -1);

    int i, j;
    while(!next.empty())
    {
        i = next.front();
        next.pop();

        for(auto &x : graf[i])
        {
            if(tavok[x] > -1) continue;

            next.push(x);
            tavok[x] = tavok[i]+1;
        }
    }

    j = tavok[i]/2;
 
    j = (j & 1)^1 ? j+1 : j;

    return j;
}

int jerry(gr &graf, int j, int &t, vector<int> &tomtavok)
{
    vector<int> jertavok(graf.size(), -1);
    jertavok[j] = 0;

    queue<int> next;
    next.push(j);
    stack<int> jok;

    int i;
    while(!next.empty())
    {
        i = next.front();
        next.pop();

        for(auto &x : graf[i])
        {
            if(jertavok[x] > -1 || tomtavok[x] <= jertavok[i]+1) continue;

            next.push(x);
            jertavok[x] = jertavok[i]+1;
            jok.push(x);
        }
    }

    int m = -1;
    while(!jok.empty())
    {
        m = tomtavok[m] > tomtavok[jok.top()] ? m : jok.top();
        jok.pop();
    }

    return tomtavok[m];
}

int main()
{
    int T;
    cin >> T;

    int n, t, j, k, nn, a, b;
    int kozep;

    while(T--)
    {
        cin >> n >> t >> j >> k;
        j--;
        t--;
        nn = n-1;

        gr graf(n);
        
        vector<int> tomtavok(n, -1);
        tomtavok[t] = 0;

        while(nn--)
        {
            cin >> a >> b;

            a--; b--;
            graf[a].push_back(b);
            graf[b].push_back(a);

        }

        nn = t;
        
        nn = bfs(graf, nn, tomtavok);

        if(tomtavok[j] == 1)
        {
            cout << "IGEN\n";
            continue;
        }

        if(jerry(graf, j, t, tomtavok) <= k)
        {
            cout << "IGEN\n";
            continue;
        }

        kozep = bfsm(graf, nn);

        cout << (kozep < k ? "IGEN" : "NEM") << "\n";
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base18/50
1Accepted0/03ms1812 KiB
2Accepted0/03ms2016 KiB
3Wrong answer0/52ms2360 KiB
4Accepted1/13ms2524 KiB
5Wrong answer0/13ms2760 KiB
6Accepted1/13ms2996 KiB
7Wrong answer0/13ms3164 KiB
8Wrong answer0/13ms3116 KiB
9Wrong answer0/13ms3120 KiB
10Wrong answer0/13ms3244 KiB
11Wrong answer0/23ms3448 KiB
12Wrong answer0/23ms3524 KiB
13Wrong answer0/13ms3656 KiB
14Wrong answer0/2167ms6376 KiB
15Wrong answer0/2155ms5036 KiB
16Accepted2/2172ms6496 KiB
17Accepted2/2157ms7876 KiB
18Accepted2/2166ms6612 KiB
19Accepted2/2171ms6696 KiB
20Accepted2/2107ms8036 KiB
21Wrong answer0/2152ms5524 KiB
22Accepted2/2155ms5528 KiB
23Wrong answer0/3157ms8656 KiB
24Accepted2/2166ms7268 KiB
25Wrong answer0/3164ms6832 KiB
26Wrong answer0/2158ms8312 KiB
27Accepted2/2152ms5812 KiB
28Wrong answer0/3153ms5920 KiB