Guest User

Untitled

a guest
Jan 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <cstdio>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. struct V {
  7.   int key;
  8.   bool passou;
  9.   vector<int> next;
  10.   vector<int> prev;
  11. };
  12. vector<V*> end;
  13. vector<int> pil;
  14. int marc;
  15. int last;
  16. void start(int qn){
  17.     for(int i=0; i<qn; i++){
  18.         V *t;
  19.         t = (V*)malloc(sizeof(V));
  20.         t->key=i;
  21.         t->passou=0;
  22.         end.push_back(& *t);
  23.     }
  24. }
  25.  
  26. void simular(int qV){
  27.     bool ligC[qV][qV];
  28.     bool hist[qV][qV];
  29.     bool noCactus=0;
  30.     marc = -1;
  31.     last=-1;
  32.     for(int i=0; i<end.size(); i++){
  33.         V *t = end[i];
  34.         if(!(t->passou)){
  35.             last = t->key;
  36.             for(int j=0; j<(t->next).size();j++,marc++){
  37.                 V *tAux = end[t->next[j]];
  38.                 pil.push_back(tAux->key);
  39.                 hist[j][last]=1;
  40.             }
  41.             t->passou=1;
  42.  
  43.         }
  44.         while(pil[0]!=NULL||noCactus){ // pode acontecer algo no NULL
  45.             V *t1 = end[pil[marc]];
  46.  
  47.             if(!(t1->passou)){
  48.                 last = t1->key;
  49.                 pil[marc] = NULL;
  50.                 marc--;
  51.                 for(int j=0; j<(t1->next).size();j++,marc++){
  52.                         V *tAux = end[t1->next[j]];
  53.                         pil.push_back(tAux->key);
  54.                         hist[j][last]=1;
  55.                         for(int l=0;l<qV;l++,hist[j][l]=1);
  56.                     }
  57.                     t->passou=1;
  58.             }else{
  59.                 V *t2 = end[last];
  60.                 int fbKey;
  61.                 int fb;
  62.                 V* t2Aux; // não sei pra que.
  63.                 while(pil[0]!=NULL||noCactus||fb==0){
  64.                     t2Aux = t2;
  65.                     fb=0;
  66.                     for(int j=0; j<t2->prev.size() ;j++){
  67.                         V *tAux = end[t2->prev[j]];
  68.                         if(hist[tAux->key][t1->key]&&!(hist[tAux->key][t2->key])) fb++, fbKey=tAux->key;
  69.                     }
  70.                     if(fb>1) noCactus=1;
  71.                 }
  72.             }
  73.         }
  74.     }
  75.     noCactus? printf("NO"):printf("YES");
  76. }
  77.  
  78.  
  79. int main(){
  80.     int q;
  81.     scanf("%d", &q);
  82.     for(int i=0; i<q; i++){
  83.         int qV, qE;
  84.         scanf("%d %d",&qV, &qE);
  85.         start(qV);
  86.  
  87.         for(int i=0; i<qE;i++){
  88.             int v1,v2;
  89.             scanf("%d %d",&v1,&v2);
  90.  
  91.             V *t1 = end[v1];
  92.             V *t2 = end[v2];
  93.             printf("%d\n%d",t1->key,t2->key);
  94.             t1->next.push_back(v2);printf("foi");
  95.             t2->prev.push_back(v1);
  96.         }
  97.     }
  98.  
  99. }
Add Comment
Please, Sign In to add comment