Beispiel #1
0
static void neighbors(Node *n, Nodes &r, NodePool &p, const Grid &g) {
  Tile v[16];
  size_t s = g.adjacent(n->tile, v, COUNTOF(v));
  r.clear();
  for (Tile *t = v; t < v + s; ++t) {
    float c = g.get(*t);
    if (c > 0.1f) {
      Node *a = new (p) Node(*t, c);
      r.push_back(a);
    }
  }
}
int main()
{
    Nodes nodes;
    Neighbors neighbors;

    int n = 0, edges = 0, index = 0, nodeX = 0, nodeY = 0;

    while (true)
    {
        cin >> n;

        if (!n)
        {
            break;
        }

        nodes.clear();
        neighbors.clear();

        for (index = 0; index < n; index++)
        {
            nodes[index] = Uncolored;
        }
        
        cin >> edges;

        while (edges)
        {
            cin >> nodeX >> nodeY;

            neighbors[nodeX].push_back(nodeY);
            neighbors[nodeY].push_back(nodeX);

            edges--;
        }

        cout << (Colorable(nodes, neighbors)? "BICOLORABLE." : "NOT BICOLORABLE.") << endl;
    }
    return 0;
}
Beispiel #3
0
void Evaluator::subst_macros()
{
    int cntr = 0;
    Token gtok(0, 0);
    while (1)
    {
        if (++cntr > MAX_SUBST)
            throw Err("Too many macro substitutions: " + bug::to_string(MAX_SUBST) + ", possible recursion", gtok);

        bool weresubs = false;

        Nodes old = root->children;
        root->children.clear();

        Nodes leftovers;
        for (auto i : old)
        {
            Instruction * pin = get<Instruction>(NOTHR, i);
            if (pin)
            {
                for (auto j : leftovers)
                    i->children[0]->children[1]->children.push_back(j);

                leftovers.clear();

                root->addChild(i);
                continue;
            }

            Macuse * u = get<Macuse>(LNFUN, i);
            gtok = u->tok();

            if (u->name() == "@end")
            {
                for (auto j : u->children[0]->children)
                    leftovers.push_back(j);
                continue;
            }

            Nodes inject = Macros(root).process_macuse(*u);

            if (!inject.empty())
            {
                Pnode pn = inject.front();
                Instruction * pin = get<Instruction>(NOTHR, pn);
                if (pin)
                {
                    for (auto j : leftovers)
                        pn->children[0]->children[1]->children.push_back(j);
                }
                else
                {
                    Macuse * pu = get<Macuse>(LNFUN, pn);
                    for (auto j : leftovers)
                        pu->children[0]->children.push_back(j);
                }

                leftovers.clear();
            }

            for (auto j : inject)
                root->addChild(j);

            weresubs = true;
        }

        if (!weresubs)
        {
            if (leftovers.empty())
                break;

            if (root->children.empty())
                throw Err("Labels used in empty program");

            throw Err("Program finishes with label (see macro definition)", root->children.back()->tok());
        }
        // this can be improved later (one extra loop)
        // when expanding macro we can detect that no new macro introduced
    } // while
}