Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<ctype.h>
- #include<stdbool.h>
- #define INFINI 10000000
- struct graphs{
- int sons[1001];
- int nbrofsons;
- int value;
- };
- typedef struct graphs graphs;
- graphs tab[1001];
- int noeudVisite[1001];
- const int NON_VISITE = 0;
- const int DEJA_VISITE = 1;
- const int EN_COURS_DE_VISITE = 2;
- bool res=false;
- bool parcousprofondeur(int noeud)
- {
- if(noeudVisite[noeud]== DEJA_VISITE)
- return false;
- if(noeudVisite[noeud]== EN_COURS_DE_VISITE)
- return true;
- noeudVisite[noeud]=EN_COURS_DE_VISITE;
- for(int i=0;i<tab[noeud].nbrofsons;i++)
- if(parcousprofondeur(tab[noeud].sons[i]))
- return true;
- noeudVisite[noeud ]=DEJA_VISITE;
- return false;
- // }
- //else {
- /*for(int i=0;i<1000;i++)
- deja[noeud]=true;
- res=true;
- //return res;
- // }
- //deja[noeud]=false;*/
- }
- int main()
- {
- int nbrofnoeuds,nbrofrelation;
- scanf("%d %d",&nbrofnoeuds,&nbrofrelation);
- for(int i=0;i<nbrofrelation;i++)
- {
- int postion,son;
- scanf("%d %d",&postion,&son);
- tab[postion].sons[tab[postion].nbrofsons]=son;
- tab[postion].nbrofsons++;
- }
- for (int noeud = 0; noeud < nbrofnoeuds; noeud++)
- res=res||parcousprofondeur(noeud);
- if(res)
- printf("OUI\n");
- else
- printf("NON\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement