Figure theory-looking for a genuine fly

Source: Internet
Author: User

One day fly was sitting in a daze in class, and suddenly he noticed a string on the table s1s2s3s4 ... SN, this string consists only of the characters "a", "B" and "C". It was a boring class, so he decided to draw a picture of the string (each point on the graph represents a character in the string, for example, Node 1 represents S1. This picture has the following features:

1. It has n points, which are labeled from 1 to N.
2. For any of the two points on the graph I and J (i? ≠? J), when the characters represented by the two are adjacent to or equal to the dictionary order, they are connected to an edge. That is, "a"-"B", "a"-"a" of such, they will have a side of the link, and "A"-"C" such as the absence of the side of the link.

Fly based on the string to draw a picture, and then erase the original string, so the desktop only left a diagram. XF heard the glorious deeds of fly, the next day decided to see the original, so he came to fly the day in the classroom in front of the table, but the scene let him stunned: a lot of pictures appeared on the table, apparently this is some ulterior motives of the classmate (Goozy?) secretly painted up. This can be nasty to the XF, so he wants to ask you to help him find out which is the fly authentic.

input

The input contains multiple sets of data. The first behavior is an integer t (1?≤? T?≤?100), representing the number of data groups, for each group of data: The first row is two integers n and m ( 1?≤? n? ≤?500,?0?≤? m≤? N (n? −?1)/2), respectively, representing the number of points on the graph and the number of edges.
Then the M line, two integers per line, ui and vi ( 1?≤? Ui,? v i? ≤? n,? u i? ≠? v i ), which represents the two points connected by an edge on the diagram. The input guarantees no heavy edges.

Output

If it is an original fly, that is, the graph is composed of the string in the title description, the output is "Yes", otherwise the output "no" (does not contain double quotation marks).

Sample Input

3

2 1
1 2

4 3
1 2
1 3
1 4

4 4
1 2
1 3
1 4
2 3

Sample Output

Yes
No
Yes

HINT

For example 1,fly see the string may look like this: AA, BB, cc ...
For example 2, the node 1 and all the other points are connected, but the nodes 2, 3, 4 are not connected, which means that the three are not adjacent, and we only have three characters, it is impossible to exist such a string to meet this picture, so this picture is not a genuine fly.
For example 3, we can construct such a string "BAAC" to satisfy this picture.

------------------------------------------------------I'm the split line ^_^------------------------------------------------- -----------

The main idea: a point may be a, B, c three values, the dictionary sequence adjacent points must have an edge, give some points of the figure, determine whether the figure is legitimate.

Problem-solving ideas: From the negative side, there is no edge of the point pair, must be a for a, a C, so the question is converted into a two-point chart to determine. However, it is important to note that staining

After that, there must be an edge between points with the same color, and no edges between points with different colors.

#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<vector>#include<queue>#include<cctype>UsingNamespace Std;#define INT __int64#define INF0x3f3f3f3fConstint MAXN=555;int Maze[MAXN][maxn];int color[MAXN];BOOL ans;voidBFS(int T,int n){Queue<Int>q;While(!q.Empty()) Q.Pop(); Color[t]=1;BOOL App=True;Used to determine whether to restore the token = =, which is the less this point Q.Push(t);While(!q.Empty()){int now= Q.Front(); Q.Pop();For(int I=1; I<= N; I++){If(now= = I)Continue;If(!maze[Now][i]&& Color[I]==-1){app=False; Q.Push(I); Color[I]=!color[Now];}If(!maze[Now][i]&& Color[Now]= = Color[I]){ans=False;Return;}}}If(App) color[t]=-1;}IntMain(){Freopen ("Input.txt", "R", stdin);int CAs;While(scanf("%d",&cas)! = EOF){While(CAS--){Memset(Maze,0,sizeof(Maze));Memset(Color,-1,sizeof(Color));int nM;scanf("%d%d",&n,&m);int UV;For(int I=0; I< m; I++){scanf("%d%d",&u,&v); Maze[u][v]= Maze[V][u]=1;} ans=True;For(int I=1; I<= N; I++){Judging negative one, if the point is not dyed, begin to dye it = =If(Color[I]==-1){BFS(IN);}}For(int I=1; I<= N; I++){If(!ans)Break;For(Int J=1; J<= N; J++){If(I= = J|| Color[I]==-1|| Color[j]==-1)Continue;Judging conditionsIf(Maze[I][j]&& Color[I]! = Color[j]){ans=False;Break;}If(!maze[I][j]&& Color[I]= = Color[j]){ans=Falsebreak;  } } if Span class= "Sh-symbol" > (Ans) printf ( Span class= "sh-string" > "Yes\n" ); else printf ( "No\n" );  } return 0               /span>              

Graph theory-looking for an authentic fly

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.