/* Copyright (c) 1997-2004 Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany) http://www.math.tu-berlin.de/polymake, mailto:polymake@math.tu-berlin.de This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version: http://www.gnu.org/licenses/gpl.txt. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ #ident "$Project: polymake $$Id: diameter.tcc 4714 2004-06-22 16:23:15Z gawrilow $" #include #include #include #include namespace polymake { namespace graph { template int diameter(const Graph& G) { const int nodes=G.nodes(); int diam=0; std::vector dist(nodes); // distances from "root" node std::list node_queue(nodes); for (int r=0; rdiam) diam=d; ++d; for (typename Entire::const_iterator e=G.out_edges(n).begin(); !e.at_end(); ++e) { const int nn=e.to_node(); if (dist[nn]<0) { node_queue.push_back(nn); dist[nn]=d; } } } } return diam; } } } // Local Variables: // mode:C++ // c-basic-offset:3 // End: