Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <cstdio>
- #include <vector>
- using namespace std;
- struct V {
- int key;
- bool passou;
- vector<int> next;
- vector<int> prev;
- };
- vector<V*> end;
- vector<int> pil;
- int marc;
- int last;
- void start(int qn){
- for(int i=0; i<qn; i++){
- V *t;
- t = (V*)malloc(sizeof(V));
- t->key=i;
- t->passou=0;
- end.push_back(& *t);
- }
- }
- void simular(int qV){
- bool ligC[qV][qV];
- bool hist[qV][qV];
- bool noCactus=0;
- marc = -1;
- last=-1;
- for(int i=0; i<end.size(); i++){
- V *t = end[i];
- if(!(t->passou)){
- last = t->key;
- for(int j=0; j<(t->next).size();j++,marc++){
- V *tAux = end[t->next[j]];
- pil.push_back(tAux->key);
- hist[j][last]=1;
- }
- t->passou=1;
- }
- while(pil[0]!=NULL||noCactus){ // pode acontecer algo no NULL
- V *t1 = end[pil[marc]];
- if(!(t1->passou)){
- last = t1->key;
- pil[marc] = NULL;
- marc--;
- for(int j=0; j<(t1->next).size();j++,marc++){
- V *tAux = end[t1->next[j]];
- pil.push_back(tAux->key);
- hist[j][last]=1;
- for(int l=0;l<qV;l++,hist[j][l]=1);
- }
- t->passou=1;
- }else{
- V *t2 = end[last];
- int fbKey;
- int fb;
- V* t2Aux; // não sei pra que.
- while(pil[0]!=NULL||noCactus||fb==0){
- t2Aux = t2;
- fb=0;
- for(int j=0; j<t2->prev.size() ;j++){
- V *tAux = end[t2->prev[j]];
- if(hist[tAux->key][t1->key]&&!(hist[tAux->key][t2->key])) fb++, fbKey=tAux->key;
- }
- if(fb>1) noCactus=1;
- }
- }
- }
- }
- noCactus? printf("NO"):printf("YES");
- }
- int main(){
- int q;
- scanf("%d", &q);
- for(int i=0; i<q; i++){
- int qV, qE;
- scanf("%d %d",&qV, &qE);
- start(qV);
- for(int i=0; i<qE;i++){
- int v1,v2;
- scanf("%d %d",&v1,&v2);
- V *t1 = end[v1];
- V *t2 = end[v2];
- printf("%d\n%d",t1->key,t2->key);
- t1->next.push_back(v2);printf("foi");
- t2->prev.push_back(v1);
- }
- }
- }
Add Comment
Please, Sign In to add comment