152702025-02-17 19:19:31TakacsAndrasTúra (75 pont)cpp17Wrong answer 15/75120ms6828 KiB
#include <bits/stdc++.h>
using namespace std;
vector<int> a,p;
vector<vector<int>> g;
bool e = false;
void dfs(int u, int pr, int cnt=0,bool f=false) {
    p[u] = pr;
    if (cnt > 0) {
        cnt = a[u];
        f = true;
    }
    a[u] = -2;
    if (cnt < 0 && !f) {
        int h = u, cnt2 = 0;
        vector<int> out;
        cnt = 0;
        while (h != -1) {
            cnt += a[h];
            cnt2++;
            out.push_back(h);
            h = p[h];
            if (cnt < 0 && cnt2 > 1) break;
        }
        reverse(out.begin(),out.end());
        cout << "NEM\n" << out.size() << '\n';
        for (int x : out) cout << x << ' ';
        cout << '\n';
        e = true;

    }
    for (int &x : g[u]) {
        if (a[x] != -2) dfs(x,u,cnt+a[x]);
        if (e) break;
    }
}
int main() {
    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        e = false;
        a.assign(n+1,0);
        p.assign(n+1,0);
        for (int i = 1; i <= n; i++) cin >> a[i];
        g.assign(n+1,vector<int>(0));
        for (int i = 0; i < n-1; i++) {
            int a,b; cin >> a >> b;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        dfs(1,-1,a[1],true);
        if (!e) cout << "IGEN\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base15/75
1Accepted0/01ms500 KiB
2Wrong answer0/01ms508 KiB
3Wrong answer0/61ms316 KiB
4Accepted3/38ms316 KiB
5Wrong answer0/38ms488 KiB
6Wrong answer0/48ms316 KiB
7Wrong answer0/48ms316 KiB
8Wrong answer0/48ms500 KiB
9Wrong answer0/282ms1072 KiB
10Wrong answer0/283ms1112 KiB
11Wrong answer0/283ms1008 KiB
12Wrong answer0/283ms1076 KiB
13Wrong answer0/285ms1048 KiB
14Wrong answer0/383ms1076 KiB
15Wrong answer0/283ms1004 KiB
16Accepted2/285ms1040 KiB
17Wrong answer0/283ms1016 KiB
18Wrong answer0/283ms1356 KiB
19Wrong answer0/382ms1376 KiB
20Wrong answer0/282ms1332 KiB
21Wrong answer0/285ms1332 KiB
22Wrong answer0/385ms988 KiB
23Accepted2/2108ms6828 KiB
24Wrong answer0/2120ms6708 KiB
25Wrong answer0/297ms3372 KiB
26Accepted2/294ms3908 KiB
27Wrong answer0/2109ms3648 KiB
28Wrong answer0/296ms3892 KiB
29Accepted2/298ms3388 KiB
30Wrong answer0/2108ms3892 KiB
31Accepted2/2103ms3892 KiB
32Accepted2/2104ms3612 KiB