HDU 1811 rank of Tetris topological sort + and check set

Source: Internet
Author: User
Tags strcmp

There are equivalent points in the input, so you want to delete them all. So only after the data has been fully entered can the relationship be built.
There are three possible outputs, each of which corresponds to the following three cases.
-Success
-Looping, that is, the number of the last point is less than the number of points entered, this is the reason for information conflict
-At the same time there are two points to zero into the queue, incomplete information

#include "stdio.h"#include "string.h"#include "stack"#include "queue"#include "vector"#include "algorithm"using namespace STD;Const intn=10000+5;intN,m,bin[n],in[n]; vector<int>S[i]; Queue<int>QintFind (intx) {if(bin[x]==x)returnXElse returnFind (Bin[x]);}intMain () {intI,j,f,a[n],b[n],cnt,fa,fb,k;Chars[n][5]; while(~scanf("%d%d", &n,&m)) { for(i=0; i<n;i++) {bin[i]=i; in[i]=0;        T[i].clear (); }memset(S,0,sizeof(s)); while(!q.empty ()) Q.pop (); Cnt=0; f=1; for(i=0; i<m;i++) {scanf("%d%s%d", &a[i],s[i],&b[i]);if(s[i][0]==' = ') {Fa=find (a[i]); Fb=find (B[i]);if(FA!=FB) BIN[FA]=FB;            cnt++; }        } for(i=0; i<m;i++) {if(strcmp(S[i],"=")==0)Continue;Else if(strcmp(S[i],">")==0) {Fa=find (a[i]); Fb=find (B[i]);if(FA==FB) {f=0; Break;}                T[fa].push_back (FB);            in[fb]++; }Else if(strcmp(S[i],"<")==0) {Fa=find (a[i]); Fb=find (B[i]);if(FA==FB) {f=0; Break;}                T[fb].push_back (FA);            in[fa]++; }        }if(f==0) {printf("conflict\n");Continue;} for(i=0; i<n;i++) {if(in[i]==0&&find (i) ==i) {Q.push (i);            cnt++; }        } while(!q.empty ()) {if(Q.size () >=2) f=0;            K=q.front (); Q.pop (); for(i=0; I<t[k].size (); i++) {in[t[k][i]]--;if(in[t[k][i]]==0) {Q.push (t[k][i]);                cnt++; }            }        }if(cnt<n)printf("conflict\n");Else if(f==0)printf("uncertain\n");Else printf("ok\n"); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.