Hdu 1811 ufset Integration

Source: Internet
Author: User

Hdu 1811 ufset Integration

 

To give a graph, you must have no rings and draw all points from one point. Qualitative judgment.

If you want to restore the algorithm and determine the tarjan with strong connectivity for the contradiction, you cannot determine the simulation to be used.

 

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
Using namespace std; int fa [30105]; int n, m; int ind [30028]; int find (int x) {if (x = fa [x]) return x; fa [x] = find (fa [x]); return fa [x];} int e [2, 100154] [3]; int head [30023]; int nume; void inline adde (int I, int j) {e [nume] [0] = j; e [nume] [1] = head [I]; head [I] = nume ++;} struct zz {int x, y; char t ;}; int ins [20009]; stack
      
        Sta; int low [20025]; int dfn [20025]; int times; int vis [20025]; int scc [20251]; int numb = 0; void tarjan (int u) {dfn [u] = low [u] = times ++; ins [u] = 1; sta. push (u); for (int j = head [u]; j! =-1; j = e [j] [1]) {int v = e [j] [0]; if (! Vis [v]) {vis [v] = 1; tarjan (v); if (low [u]> low [v]) low [u] = low [v];} else if (ins [v]) {if (dfn [v]
       
         Temp; for (int I = 0; I
        
          1) return 2; numv --;} return 0;} void init () {for (int I = 0; I <10005; I ++) {fa [I] = I; head [I] =-1; low [I] = dfn [I] = 0; scc [I] = vis [I] = ins [I] = ind [I] = 0;} numb = times = nume = 0;} int main () {while (~ Scanf (% d, & n, & m) {int marks = 0; int aa, bb; char temp; init (); vector
         
           My; for (int I = 0; I
          
            > Aa> temp> bb; if (temp = ') {int xx = find (aa); int yy = find (bb); if (xx! = Yy) fa [xx] = yy;} else {zz cur; cur. x = aa; cur. y = bb; cur. t = temp; my. push_back (cur) ;}}for (int I = 0; I
           
            

 

Traditional Method: ufset topology:

 

#include
             
              #include
              
               #include
               
                #include
                
                 #include
                 
                  using namespace std;const int maxn=100004;int fa[maxn];  int n,m; int ind[maxn];int sums=0;vector
                  
                    >e(maxn);int find(int x){ if(x==fa[x])return x; fa[x]=find(fa[x]); return fa[x];}struct zz{ int x,y; char t;};int judge(){ int ans=0; stack
                   
                    mys; for(int i=0;i
                    
                     my; for(int i=0;i
                     
                      >aa>>temp>>bb; if(temp=='=') { int xx=find(aa); int yy=find(bb); if(xx!=yy){fa[xx]=yy;sums--;} } else { zz cur; cur.x=aa;cur.y=bb;cur.t=temp; my.push_back(cur); } } for(int i=0;i
                      
                       ') { int xx=find(my[i].x); int yy=find(my[i].y); e[xx].push_back(yy); ind[yy]++; } } int ans=judge(); if(n==0) ans=0; if(ans==2) printf(UNCERTAIN); else if(ans==1) printf(CONFLICT); else printf(OK); } return 0;}
                      
                     
                    
                   
                  
                 
                
               
              
             


 

 

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.