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