#include <stdio.h>
#include <stdlib.h>

struct vector_t{
    int* data;
    int capacity;
};

struct vector_t* resize_t(struct vector_t* vect, int max){
    if(vect->capacity < max){
        vect->data = (int*)realloc(vect->data, max+1);
        vect->data[max] = 0;
    }
    return vect;
}

int main(){
    struct vector_t* vect = (struct vector_t*)malloc(sizeof(struct vector_t));
    vect->capacity = 10;
    vect->data = (int*)calloc(10, sizeof(int));

    int N = 0, U = 0, V = 0, Q = 0, M = 0;
    int* ans;

    do{
        printf("Enter N: ");
        scanf("%d", &N);
    }while(N < 1 || N > 100000);

    for(int i = 0; i < N - 1; i++){
        printf("Enter U - under, V - number: ");
        scanf("%d %d", &U, &V);
        getchar();
        printf("U: %d\n", U);
        resize_t(vect, U);
        vect->data[U] += 1;
    }

    printf("%d\n", vect->data[2]);

    do{
        printf("Enter Q: ");
        scanf("%d", &Q);
    }while(Q < 1 || Q > N);

    ans = (int*)malloc(sizeof(int) * Q);

    for(int i = 0; i < Q; i++){
        printf("Enter Number: ");
        scanf("%d", &M);
        ans[i] = vect->data[M];

        printf("ans[i]: %d\n", ans[i]);
    }

    for(int i = 0; i < Q; i++)
        printf("%d", ans[i]);

    free(vect);

    return 0;
}
