HDU 1811 rank of Tetris (topological sort + and check set)

Source: Internet
Author: User

1#include"Cstdio"2#include"iostream"3#include"CString"4#include"Vector"5#include"Queue"6 using namespacestd;7 Const intN =10005;8 intN, M, T;9 intFa[n];Ten intRank[n]; One intx[2*n],y[2*N]; A intSon[n]; - Charo[2*N]; -vector<int>G[n]; the  - voidInitintN) - { -      for(inti =0; I <= N; ++i) +Fa[i]=i, rank[i]=0; -      for(inti =0; I <= N; ++i) + g[i].clear (); AMemset (son,0,sizeof(son)); at } - intFindintx) - { -     returnFA[X] = fa[x] = = x?X:find (fa[x]); - } -  in BOOLMerg (intXinty) - { to     intFX =find (x); +     intFY =find (y); -     if(FX = = FY)return false; the     if(Rank[fx] >Rank[fy]) *FA[FY] =FX; $     Else {Panax Notoginseng         if(RANK[FX] = =Rank[fy]) -++Rank[fy]; theFA[FX] =fy; +     } A     return true; the } +  - intMain () $ { $     intu, v; -     Charch; -      while(Cin >> N >>m) { the init (n); -         intnum =N;Wuyi          for(inti =0; i < m; ++i) { theCIN >> X[i] >> O[i] >>Y[i]; -             if(O[i] = ='=') { Wu                 if(Merg (X[i],y[i])) -num--; About             } $         } -          for(inti =0; i < m; + + i)if(O[i]! ='=') { -             intx =find (X[i]); -             inty =find (Y[i]); A             if(O[i] = ='>') { + g[x].push_back (y); theson[y]++; -             } $             Else { the g[y].push_back (x); theson[x]++; the             } the         } -queue<int>Q; in          for(inti =0; i < n; ++i) the             if(Son[i] = =0&& i = =find (i)) the Q.push (i); About         intSin =0; the          while(!Q.empty ()) { the             if(Q.size () >1) sin =1; the             intt =Q.front (); + Q.pop (); ---num; the              for(intv =0; v < g[t].size (); ++v) {Bayi                 if(--son[g[t][v]] = =0) the Q.push (G[t][v]); the             } -         } -         if(Num >0) cout <<"CONFLICT"<<Endl; the         Else if(sin) cout <<"uncertain"<<Endl; the         Elsecout <<"OK"<<Endl; the     } the     return 0; -}
Code Porter

Unfamiliar points:

1. And check the set by the rank compression

2.vector Building Map

3.BFS topology sequencing

HDU 1811 rank of Tetris (topological sort + and check set)

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.