/* Condominio (selezioni nazionali 2002) Copyright (C) 2002 Sebastiano Vigna 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. 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. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Questa soluzione (che non era previsto venisse trovata) è l'unica in grado di enumerare tutti i cicli nei vincoli di tempo. È un algoritmo CAT (tempo ammortizzato costante) pubblicato in D. B. Johnson, Finding all the elementary circuits of a directed graph SIAM J. Comput., 4(1), pp. 77-84, March 1975. */ #include #include #define MAXN 1000 /* Numero di nodi e archi complessivi del grafo. */ int N, M; char G[MAXN][MAXN]; /* Matrice di adiacenza. */ char b[MAXN]; /* I nodi bloccati. */ int B[MAXN][MAXN]; /* Per ogni nodo v, la lista di nodi che vanno sbloccati quando v viene sbloccato. */ int lB[MAXN]; /* La lunghezza di ciascuna lista. */ int blocca[MAXN][MAXN]; /* Matrice di comodo: B[u][i] = v per qualche i 0) { lB[u]--; blocca[u][B[u][lB[u]]] = 0; if (b[B[u][lB[u]]]) sblocca(B[u][lB[u]]); } } int circuito(int v) { int i, j, w, f=0; pila[l++] = v; /* v sulla pila */ b[v] = 1; for(i=0; i 1) { /* Azzera le informazioni di blocco per i vertici nella componente. */ for(i=0; i