Hdu 1811-Rank of RIS (query set + topological sorting)

Source: Internet
Author: User

/*

Query set processing =, and then sort the topology. When there are more than one element in the team, the conditions are insufficient. If the conditions are not used up, a conflict occurs.

*/

# Include <cstdio>

# Include <cstring>
# Include <vector>
# Include <queue>
Using namespace std;
Int u [10010], v [10010], p [10010], deg [10010];
Char opr [10010];
Vector <int> G [10010];
Int sum;
Int find (int x)
{
Return x = p [x]? X: p [x] = find (p [x]);
}
Int init (int n)
{
For (int I = 0; I <= n; I ++)
{
P [I] = I;
G [I]. clear ();
Deg [I] = 0;
}
}
Int topo (int n)
{
Queue <int> q;
For (int I = 0; I <n; I ++)
If (! Deg [I] & find (I) = I)
Q. push (I );
Int flag = 0;
While (! Q. empty ())
{
If (q. size ()> 1) flag = 1;
Int x = q. front ();
Q. pop ();
Sum --;
For (int I = 0; I <G [x]. size (); I ++)
{
Int y = G [x] [I];
If (-- deg [y] = 0)
{
Q. push (y );
}
}
}
If (sum> 0) puts ("CONFLICT ");
Else if (flag) puts ("UNCERTAIN ");
Else puts ("OK ");
}
Int main ()
{
Int n, m;
While (scanf ("% d", & n, & m) = 2)
{
Init (n );
Sum = n;
For (int I = 0; I <m; I ++)
{
Scanf ("% d % c % d", & u [I], & opr [I], & v [I]);
If (opr [I] = ')
{
Int x = find (u [I]);
Int y = find (v [I]);
If (x! = Y)
{P [y] = x;
Sum --;}
}
}
For (int I = 0; I <m; I ++)
{
If (opr [I] = ') continue;
Int x = find (u [I]);
Int y = find (v [I]);
If (opr [I] = '> ')
{
G [x]. push_back (y );
Deg [y] ++;
}
Else
{
G [y]. push_back (x );
Deg [x] ++;
}
}
Topo (n );
}
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.