#include #include #if 0 #define N 4 #define A 6 #elif 0 #define N 10 #define A (2*N) #else #define X 7 #define Y 9 #define Z (X+Y+1) #define N ((X+1)*(Y+1)) #define A (6*N) #endif typedef char graphe1[N][N]; typedef int sommet; typedef sommet graphe2[2*A]; typedef struct maillon maillon, *liste; struct maillon { sommet s; liste next; } ; typedef liste graphe3[N]; void affg1(graphe1 g1) { for(int i=0;i%d ",i,j); printf("\n"); } void affg2(graphe2 g2) { for(int k=0;k<2*A;k+=2) printf("%d-->%d ",g2[k],g2[k+1]); printf("\n"); } void affg3(graphe3 g3) { for(int i=0;inext) printf("%d-->%d ",i,l->s); printf("\n"); } void g1g2(graphe1 g1, graphe2 g2) { for(int i=0;is=j, t->next=l, l=t++; g3[i]=l; } } void g2g1(graphe2 g2, graphe1 g1) { for(int i=0;is=g2[k+1], t->next=g3[i], g3[i]=t++; } } void g3g1(graphe3 g3, graphe1 g1) { for(int i=0;inext) g1[i][l->s]=1; } } void g3g2(graphe3 g3, graphe2 g2) { for(int i=0;inext) *g2++=i, *g2++=l->s; } void retourneg1(graphe1 g1) { for(int i=0;is; p->s=i; liste q=p->next; p->next=g3[j], g3[j]=p, p=q; } } int cherchecfc1(graphe1 g1, int cfc[N]) { int nbcfc=0, nbfin=0, fin[N]; void parcours1(int s) { cfc[s]=-1; for(int i=0;inext) if(!cfc[p->s]) parcours1(p->s); fin[nbfin++]=s; } void parcours2(int s) { cfc[s]=nbcfc; for(liste p=g3[s];p;p=p->next) if(cfc[p->s]<0) parcours2(p->s); } int i; for(i=0;inext) if(!cfc[p->s]) parcours1(p->s); fin[nbfin++]=s; } void parcours2(int s) { cfc[s]=nbcfc; for(liste p=g3[s];p;p=p->next) if(cfc[p->s]<0) parcours2(p->s); } int i; for(i=0;inext) if(dist[i=p->s]<0) dist[file[in++]=i]=dist[s]+1, pere[i]=s; } } void pluscourt3(graphe3 g3,sommet s,int dist[N],int pere[N]) { int file[N], in=0, out=0, i; for(i=0;inext) if(dist[i=p->s]<0) dist[file[in++]=i]=dist[s]+1, pere[i]=s; } } void affpluscourt(int pere[N],int b) { if(pere[b]<0) printf("pas de chemin vers"); else if(pere[b]!=b) affpluscourt(pere,pere[b]); printf(" %d",b); } void minimise(int *a,int b) { if(b<*a) *a=b; } int cherchecfc3pile(graphe3 g3,int cfc[N]) { int num[N], min[N], c=0, pile[N], ip=0, nbcfc=N, i; int parcours(int s) { if(cfc[s]>=0) return N; if(min[s]>=0) return min[s]; num[s]=min[s]=c++, pile[ip++]=s; for(liste p=g3[s];p;p=p->next) minimise(min+s,parcours(p->s)); if(min[s]==num[s]) for(nbcfc--;cfc[pile[--ip]]=nbcfc,s!=pile[ip];) ; return min[s]; } for(i=0;i=0) return cfc[s]; cfc[s]=c++, pile[ip++]=s; for(liste p=g3[s];p;p=p->next) minimise(cfc+s,parcours(p->s)); if(cfc[s]==--c) for(nbcfc--;cfc[pile[--ip]]=nbcfc,s!=pile[ip];) ; return cfc[s]; } for(i=0;is]),p=p->next) if(cfc[p->s]<0) parcours(p->s); if(cfc[s]==--c) for(nbcfc--;cfc[pile[--ip]]=nbcfc,s!=pile[ip];) ; } for(i=0;i=0) goto sortie; pile2[cfc[s]=c++]=pile[ip++]=s; // for(;g3[s];minimise(cfc+s,cfc[g3[s]->s]),g3[s]=g3[s]->next) if(cfc[g3[s]->s]<0) parcours(g3[s]->s); next: if(g3[s]) { s=g3[s]->s; goto entree; } if(cfc[s]==--c) for(nbcfc--;cfc[pile[--ip]]=nbcfc,s!=pile[ip];) ; sortie: if(!c) continue; s=pile2[c-1], minimise(cfc+s,cfc[g3[s]->s]), g3[s]=g3[s]->next; goto next; } for(i=0;i