Rezultati

Up. imeNalogaJezikRezultatČas oddaje
finalsolution-2018 Nič nas ne sme presenetiti! C 100/100OK 19. apr '18 @ 18:41

Test Točke Porabljen spomin Porabljen čas Status
#1 12/12 1,449 MiB 0,000 s OK
#2 12/12 1,449 MiB 0,016 s OK
#3 12/12 1,355 MiB 0,000 s OK
#4 12/12 4,855 MiB 0,115 s OK
#5 13/13 1,449 MiB 0,000 s OK
#6 13/13 7,527 MiB 0,108 s OK
#7 13/13 4,477 MiB 0,111 s OK
#8 13/13 4,480 MiB 0,141 s OK

Ocenjevani program (nnnp.c):
#include <stdio.h>

struct road {
    int next;
    int town;
};

static int N = 0;
static int H[100001];
static int P[100001];
static int D[100001];
static int C[100001];
static int T[100001];
static struct road R[200000];

static void buildtree(int i, int p, int d) {
    if (D[i]) return;
    P[i] = p;
    D[i] = d;
    int j = H[i];
    while (j > 0) {
        buildtree(R[j].town, i, d + 1);
        j = R[j].next;
    }
}

static int walktree(int i) {
    if (T[i] != -1) return T[i];
    int t = walktree(P[i]);
    if (t == 0) t = i;
    T[i] = t;
    return t;
}

int main() {
    int i = 0, q = 0, r = 1;
    scanf("%d %d", &N, &q);
    for (i = 1; i < N; i++) {
        int a = 0, b = 0;
        scanf("%d %d", &a, &b);
        int ra = r++;
        int rb = r++;
        R[ra].next = H[a];
        R[rb].next = H[b];
        R[ra].town = b;
        R[rb].town = a;
        H[a] = ra;
        H[b] = rb;
    }
    buildtree(1, 0, 1);
    while ((q--) > 0) {
        int m = 0;
        scanf("%d", &m);
        for (i = 0; i < m; i++) {
            scanf("%d", &C[i]);
            T[C[i]] = -1;
        }
        int t = walktree(C[0]);
        for (i = 1; i < m; i++) {
            if (walktree(C[i]) != t) break;
        }
        if (i == m) printf("ALAAAARHM\n");
        else printf("NASLEDNJI\n");
        for (i = 0; i < m; i++) {
            T[C[i]] = 0;
        }
    }
    return 0;
}