HDU 1811 topology sort + and check set + careful

Source: Internet
Author: User

Test instructions and methods are very simple, just need to pay attention to a lot of places, such as the edge of the beginning of the end may be in a set, as well as conflict is not the case of the priority to judge the conflict.

1#include <iostream>2#include <cstring>3#include <cstdio>4#include <queue>5 using namespacestd;6 7 Const intN =10000;8 Const intM =20000;9 intF[n];Ten intHead[n]; One int inch[N]; A intN, M, E, sum; -  - intFINDF (intx) the { -     if(f[x]! = x) F[x] =findf (f[x]); -     returnF[x]; - } +  - voidUnion_set (intXinty) + { Ax = FINDF (x), y =findf (y); at     if(X! =y) -     { -F[X] =y; -     } - } -  in structOp - { to     intA, B; +     Charr[2]; - } Op[m]; the  * structEdge $ {Panax Notoginseng     intV, next; - } Edge[m]; the  + voidAddedge (intUintv) A { theEDGE[E].V =v; +Edge[e].next =Head[u]; -Head[u] = e++; $ } $  - intMain () - { the      while(SCANF ("%d%d", &n, &m)! =EOF) -     {WuyiE =0; thesum =N; -Memset (Head,-1,sizeof(head)); WuMemsetinch,0,sizeof(inch) ); -          for(inti =0; I < n; i++) F[i] =i; About          for(inti =0; I < m; i++ ) $         { -scanf"%d%s%d", &AMP;OP[I].A, OP[I].R, &op[i].b); -             if(op[i].r[0] =='=' ) -             { Asum--; + Union_set (OP[I].A, op[i].b); the             } -         } $         BOOLFLAG0 =false; the          for(inti =0; I < m; i++ ) the         { the             if(op[i].r[0] =='=')Continue; the             intA = FINDF (op[i].a), B =findf (op[i].b); -             if(A = =b) in             { theFLAG0 =true; the                  Break; About             } the             if(op[i].r[0] =='<' ) the             { the Addedge (b, a); +                 inch[a]++; -             } the             ElseBayi             { the Addedge (A, b); the                 inch[b]++; -             } -         } the         if(FLAG0) the         { thePuts"CONFLICT"); the             Continue; -         } thequeue<int>Q; the          for(inti =0; I < n; i++ ) the         {94             if( !inch[i] && f[i] = =i) Q.push (i); the         } the         BOOLFlag1 =false; the          while( !q.empty ())98         { About             if(Q.size () >1) Flag1 =1; -             intU =Q.front ();101 Q.pop ();102sum--;103              for(inti = Head[u]; I! =-1; i =edge[i].next)104             { the                 intv =edge[i].v;106                 inch[v]--;107                 if(inch[v] = =0 )108                 {109 Q.push (v); the                 }111             } the         }113         if(Sum >0 ) the         { thePuts"CONFLICT"); the         }117         Else118         {119             if(Flag1) puts ("uncertain"); -             ElsePuts"OK");121         }122     }123     return 0;124}

HDU 1811 topology sort + and check set + careful

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.