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)