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;
}
Пример #2
0
int main(int argc, char *argv[]) {


  std::string input;
  int width;
  int height;
  int row = 0;
  int attempt = 0;

  while(std::getline(std::cin, input)) {
    char c = input.at(0);
    if(c == '.' || c == 'X' || c == '*') {
      ++row;
      neighbors.clear();
      for(int pos = 0; pos < (int) input.length(); ++pos) {
        VertexWeight vertexWeight;
        vertexWeight.first = pos;
        char temp = input.at(pos);
        if(temp == '.') {
          vertexWeight.second = 1;
        } else if(temp == '*') {
          vertexWeight.second = 2;
        } else {
          vertexWeight.second = 3;
        }
        neighbors.push_back(vertexWeight);
      }
      adjList.push_back(neighbors);
      if(height == row) {
        visited.clear();
        for(int index = 0; index < height; ++index) {
          visited.push_back(std::vector<bool>(width, false));
        }
        for(int i = 0; i < height; ++i) {
          for(int j = 0; j < width; ++j) {
            if((visited[i])[j] == false && ((adjList[i])[j]).second != 1) {
              area = 0;
              floodFill(i, j, ((adjList[i])[j]).second);
              if(area)
              areas.push_back(area);
            }
          }
        }

        std::cout << "Throw " << ++attempt << std::endl;
        std::sort(areas.begin(), areas.end());
        int numAreas = (int)areas.size() - 1;
        for(std::vector<int>::iterator it = areas.begin(); it != areas.end(); ++it) {
          std::cout << *it;
          if(numAreas--) {
            std::cout << " ";
          }
        }
        std::cout << std::endl;
        std::cout << std::endl;
      }
    } else {
      row = 0;

      std::stringstream sbuf;
      sbuf << input;
      sbuf >> width >> height;

      adjList.clear();
      areas.clear();

      if(width == 0 && height == 0) {
        break;
      }
    }
  }
  return 0;
}