hdu1811 rank of Tetris and search set + topological sort

Source: Internet
Author: User

1#include <stdio.h>2#include <string.h>3#include <vector>4#include <queue>5 using namespacestd;6 structNode//side7 {8     intA, B;//Vertex9     CharCh//operatorTen}c[10005]; Onevector<int>map[10005];//Map Array Storage adjacency table (The big guy is so open array) A intN, m, Sum,inch[10005], fa[10005];//in Array, Fa[i] represents the root node of the collection where vertex i resides -  - intFindintX//Find root node the { -     if(fa[x]! = x) Fa[x] =find (Fa[x]); -     returnFa[x]; - } +  - BOOLComb (intXintY//Merging Collections + { Ax =find (x); aty =find (y); -     if(x = =y) -         return false; -     Else -     { -Fa[y] =x; in         return true; -     } to } +  - voidInit ()//Initialize the { *      for(inti =0; i<n; i++) $Fa[i] =i;Panax Notoginseng } -  the voidTop_sort ()//Queue implementation topology sequencing + { Aqueue<int>s; the     intFlag =0; +      for(inti =0; i<n; i++) -     { $         //find the tangent of the zero in the ancestors for their own affiliation to the queue $         if(inch[I] = =0&& Fa[i] = =i) - S.push (i); -     } the      while(!s.empty ()) -     {Wuyi         if(S.size () >1)//Keep running even if you find the information incomplete, because if the information is incomplete and the conflict is conflict theFlag =1; -         intpos =S.front (); WuS.pop (), sum--;//number of times the record was run -          for(inti =0; I<map[pos].size (); i++) About         { $             inch[map[pos][i]]--; -             if(inch[Map[pos][i]] = =0) - S.push (Map[pos][i]); -         } A     } +     if(sum>0) printf ("conflict\n");//conflict, that is, there are multiple degrees of zero and ancestors for their own appearance the     Else if(flag) printf ("uncertain\n"); -     Elseprintf"ok\n"); $ } the  the intMain () the { the      while(SCANF ("%d%d", &n, &m)! =EOF) -     { insum =N; the init (); thememset (Map,0,sizeof(map)); AboutMemsetinch,0,sizeof(inch)); the          for(inti =0; i<m; i++) the         { thescanf"%d%c%d", &AMP;C[I].A, &c[i].ch, &c[i].b); +             //merges into the same collection if they are equal -             if(c[i].ch = ='=') the             {Bayi                 if(Comb (c[i].a, c[i].b)) thesum--; the             } -         } -          for(inti =0; i<m; i++) the         { the             if(c[i].ch = ='=') the                 Continue; the             intx =find (C[I].A); -             inty =find (c[i].b); the             if(c[i].ch = ='>') the             { the map[x].push_back (y);94                 inch[y]++; the             } the             Else the             {98 map[y].push_back (x); About                 inch[x]++; -             }101         }102 Top_sort ();103     }104     //System ("pause"); the     return 0;106}

hdu1811 rank of Tetris and search set + topological sort

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.