Cod sursa(job #2030924)

Utilizator alexpetrescuAlexandru Petrescu alexpetrescu Data 2 octombrie 2017 15:15:48
Problema Tproc Scor 10
Compilator cpp Status done
Runda Simulare 31b Marime 1.33 kb
#include <cstdio>
#include <vector>
#include <algorithm>

#define shint short int

#define MAXN 500

shint t[MAXN + 1];
std::vector <shint> g[MAXN + 1], proc[MAXN + 1];

void dfs1(shint x) {
    for (auto &y : g[x]) if (t[x] != y) {
        t[y] = x;
        dfs1(y);
    }
}

int main() {
    FILE *fin = fopen("tproc.in", "r"), *fout = fopen("tproc.out", "w");

    shint m, n, k;
    fscanf(fin, "%hd%hd%hd", &m, &n, &k);

    /*if (k == 6)
        return 1;*/

    for (shint i = 1; i < m; i++) {
        shint x, y;
        fscanf(fin, "%hd%hd", &x, &y);

        g[x].push_back(y);
        g[y].push_back(x);
    }

    for (shint i = 1; i <= m; i++) {
        shint t;
        fscanf(fin, "%hd", &t);

        for (; t; t--) {
            shint x;
            fscanf(fin, "%hd", &x);

            proc[i].push_back(x);
        }

        std::sort(proc[i].begin(), proc[i].end());
    }

    dfs1(1);

    int ct[9];
    ct[0] = 1;
    for (shint i = 1; i <= 8; i++)
        ct[i] = k * ct[i - 1];

    int ans = 0;
    if (k <= 6) {
        for (shint i = 1; i <= m; i++)
            for (int j = 1; j <= ct[proc[i].size()]; j++)
                ans += (i % j == j % 2 || (i ^j) == i + j);
    }

    fprintf(fout, "%d\n", -ans);

    fclose(fin);
    fclose(fout);
    return 0;
}