{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"I was given the task to make all the major two way roads in Bangladesh into one way roads. And I have done that easily with some great pruning. And I asked the Govt. Traffic Management System to change the direction of all the roads.\n\nBut after some days, I realized that I should have thought of the fact that all cities should be reachable from other cities using the existing one way roads. Since the traffic system is already designed, so it may not be changed. But I can ask the govt. to build new roads between any pair of cities.\n\nNow since the task looks quite hard for me, I am asking you to do it for me. I will give you the current roads configuration. You have to find the minimum number of roads that have to be built such that it\u0027s possible to go from any city to any other city."}},{"title":"Input","value":{"format":"MD","content":"Input starts with an integer **T (\u0026#8804; 25)**, denoting the number of test cases.\n\nEach case starts with a blank line. Next line contains two integers **n (1 \u0026#8804; n \u0026#8804; 20000)** and **m (0 \u0026#8804; m \u0026#8804; 50000)**, where **n** denotes the number of cities and **m** denotes the number of one way roads. Each of the next **m** lines contains two integers **u v (1 \u0026#8804; u, v \u0026#8804; n, u \u0026#8800; v)** meaning that there is a road from **u** to **v**. Assume that there can be at most one road from a city **u** to **v**."}},{"title":"Output","value":{"format":"MD","content":"For each case, print the case number and the minimum number of roads that have to be built."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\n\n3 0\n\n3 2\n1 2\n1 3\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1: 3\nCase 2: 2\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"MD","content":"Dataset is huge. Use faster I/O methods."}}]}