Hoj 3005 game Rigging

Source: Internet
Author: User

/*

 

Question:

Now we will show you how to compare the abilities of contestants and the numbers of participating friends. How can we organize the competitions so that our friends can win?

 

Analysis:

A directed graph can be constructed for each contestant's ability to make his friend win the game, so his connected Block

It must be 0 (assuming that a person with high capability is used as the starting point of the edge when creating a graph ). So the question can be converted to the first graph, and then

Find the connected block to find the contraction point, and then determine whether the contraction point is 0. If a friend is in the connected block, you can determine whether the contraction point can be organized like this.

. To determine whether a friend is not in the connected block, you can first find all connected blocks with 0 inbound values and set them to true using arrays,

Then directly set the connected block where all friends are located to false. If there is a true connected block in all connected blocks, you can judge

Cannot organize such a competition

 

*/

# Include <cstdio>

# Include <cstring>

 

Const int x = 100005;

 

Int dfn [X], low [X], stack [X], deg [X], Father [X], depth, top, bcnt;

Int f [X], Fri, n, m;

Bool use [X], instack [x];

 

Struct Node

{

Int V;

Node * next;

Void fun ()

{

V = 0;

Next = NULL;

}

} Edge [X], * head [X], * TMP;

 

Void Tarjan (int u)

{

Int V;

Dfn [u] = low [u] = ++ depth;

Stack [++ top] = u;

Instack [u] = true;

 

For (node * P = head [u]; P = p-> next)

{

V = p-> V;

If (! Low [v])

{

Tarjan (v );

If (low [v] <low [u])

Low [u] = low [v];

}

Else if (instack [v] & low [u]> dfn [v])

Low [u] = dfn [v];

}

If (low [u] = dfn [u])

{

Bcnt ++;

Do

{

V = stack [top --];

Instack [v] = false;

Father [v] = bcnt;

} While (u! = V );

}

}

 

Void solve ()

{

Memset (instack, false, sizeof (instack ));

Memset (low, 0, sizeof (low ));

Memset (deg, 0, sizeof (DEG ));

Depth = bcnt = Top = 0;

 

For (INT I = 1; I <= N; I ++)

If (! Low [I])

Tarjan (I );

 

For (INT I = 1; I <= N; I ++)

For (node * P = head [I]; P = p-> next)

If (father [I]! = Father [p-> V])

DEG [Father [p-> V] ++;

 

Memset (use, false, sizeof (use ));

For (INT I = 1; I <= bcnt; I ++)

If (! DEG [I])

Use [I] = true;

 

For (INT I = 0; I <Fri; I ++)

Use [Father [f [I] = false;

 

Bool flag = true;

For (INT I = 1; I <= bcnt; I ++)

If (use [I])

{

Flag = false;

Break;

}

Flag? Printf ("Yes \ n"): printf ("NO \ n ");

}

 

Int main ()

{

Freopen ("sum. In", "r", stdin );

Freopen ("sum. Out", "W", stdout );

While (scanf ("% d", & N, & Fri, & M), N | M | Fri)

{

For (INT I = 0; I <Fri; I ++)

Scanf ("% d", & F [I]);

Memset (Head, null, sizeof (head ));

 

For (INT I = 0; I <m; I ++)

Edge [I]. Fun ();

TMP = edge;

Int U, V;

For (INT I = 0; I <m; I ++)

{

Scanf ("% d", & U, & V );

TMP-> next = head [u];

TMP-> V = V;

Head [u] = TMP ++;

}

Solve ();

}

 

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.