154272025-02-19 15:14:45PKBTúra (75 pont)cpp17Accepted 75/7556ms6452 KiB
#include <iostream>
#include <vector>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vector<int> beauty(n+1);
        for(int i = 1; i <= n; i++){
            cin >> beauty[i];
        }

        if(n == 1){
            cout << "IGEN" << "\n";
            continue;
        }

        vector<vector<int>> adj(n+1);
        bool foundCandidate = false;

        pair<int,int> candidateEdge(-1, -1);


        for(int i = 1; i <= n-1; i++){
            int u, v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);

            if(beauty[u] == -1 && beauty[v] == -1){
                foundCandidate = true;
                candidateEdge = {u, v};
            }
        }


        if(foundCandidate){
            cout << "NEM" << "\n";
            cout << 2 << "\n";
            cout << candidateEdge.first << " " << candidateEdge.second << "\n";
            continue;
        }

        bool foundTriplet = false;
        int triplet_center = -1, neg1 = -1, neg2 = -1;
        for(int u = 1; u <= n; u++){
            if(beauty[u] == 1){
                int cnt = 0;
                int firstNeg = -1, secondNeg = -1;
                for(auto v : adj[u]){
                    if(beauty[v] == -1){
                        cnt++;
                        if(firstNeg == -1) firstNeg = v;
                        else if(secondNeg == -1) secondNeg = v;
                    }
                }
                if(cnt >= 2){
                    foundTriplet = true;
                    triplet_center = u;
                    neg1 = firstNeg;
                    neg2 = secondNeg;
                    break;
                }
            }
        }

        if(foundTriplet){
            cout << "NEM" << "\n";
            cout << 3 << "\n";
            cout << neg1 << " " << triplet_center << " " << neg2 << "\n";
            continue;
        }


        cout << "IGEN" << "\n";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/01ms508 KiB
2Accepted0/01ms316 KiB
3Accepted6/61ms316 KiB
4Accepted3/34ms316 KiB
5Accepted3/34ms484 KiB
6Accepted4/44ms556 KiB
7Accepted4/44ms484 KiB
8Accepted4/44ms484 KiB
9Accepted2/243ms828 KiB
10Accepted2/243ms1020 KiB
11Accepted2/243ms900 KiB
12Accepted2/243ms1096 KiB
13Accepted2/243ms1024 KiB
14Accepted3/343ms828 KiB
15Accepted2/243ms828 KiB
16Accepted2/245ms828 KiB
17Accepted2/243ms828 KiB
18Accepted2/241ms984 KiB
19Accepted3/341ms824 KiB
20Accepted2/241ms828 KiB
21Accepted2/243ms1004 KiB
22Accepted3/343ms976 KiB
23Accepted2/250ms6452 KiB
24Accepted2/256ms6136 KiB
25Accepted2/248ms3284 KiB
26Accepted2/245ms3536 KiB
27Accepted2/250ms3276 KiB
28Accepted2/248ms3532 KiB
29Accepted2/250ms3392 KiB
30Accepted2/246ms3600 KiB
31Accepted2/250ms3532 KiB
32Accepted2/254ms3280 KiB