Associated Course(s):
Geeks Classes in Noida

Given an undirected graph and an integer **M**. The task is to determine if the graph can be colored with at most M colors such that no two adjacent vertices of the graph are colored with the same color. Here coloring of a graph means assignment of colors to all vertices. Print 1 if it is possible to colour vertices and 0 otherwise.

Vertex are 1-based (vertext number starts with 1, not 0).

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of four lines. The first line of each test case contains an integer N denoting the number of vertices. The second line of each test case contains an integer M denoting the number of colors available. The third line of each test case contains an integer E denoting the number of edges available. The fourth line of each test case contains E pairs of space separated integers denoting the edges between vertices.

**Output:**

Print the desired output.

**Constraints:**

1 <= T <= 30

1 <= N <= 50

1 <= E <= N*(N-1)

1 <= M <= N

**Example:**

**Input :**

2

4

3

5

1 2 2 3 3 4 4 1 1 3

3

2

3

1 2 2 3 1 3

**Output:**

1

0

**Explanation:
Testcase 1:** It is possible to colour the given graph using 3 colours.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

VISHESHA SADU | 27 |

ghanshyam648 | 25 |

Biswajit3 | 21 |

karthik_kasaragadda | 20 |

tanya_sharma | 18 |

KshatriyaYash | 1066 |

nikhil_sojan | 978 |

lonecoder | 935 |

mazumderrohit8 | 864 |

SumitSingh27 | 832 |

blackshadows | 5327 |

Ibrahim Nash | 5215 |

akhayrutdinov | 5111 |

mb1973 | 4468 |

Quandray | 4444 |

Login to report an issue on this page.