F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Rikka with Linker

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 60    Accepted Submission(s): 11


Problem Description
You will be familiar with the linker of C++ if you have ever compiled C++ projects in the command line. If you want to use two static libraries $liba.a$ and $libb.a$ while $liba.a$ relies on $libb.a$, you need to put $liba.a$ before $libb.a$ in your command such as $g++$ $-o$ $my$ $my.cpp$ $liba.a$ $libb.a$.

What if both $liba.a$ and $libb.a$ rely on each other? You need to add their names to the command several times such as $g++$ $-o$ $my$ $my.cpp$ $liba.a$ $libb.a$ $liba.a$. Formally, if you want to use two libraries $liba.a$ and $libb.a$ while $liba.a$ relies on $libb.a$ in your command, there must be at least one $liba.a$ which occurs before one $libb.a$.

Now, Rikka is working on her C++ project, and there are $n$ static libraries she will use. There are $m$ pairs of dependency relationships $(i, j)$ which means the $i$th project relies on the $j$th project.

You know, a complicated command will never bring happiness. So Rikka wants to simplify the compile command, i.e., Rikka wants to make the number of the names of static libraries in her compile command as small as possible. So she wants you to find out this number.
 

Input
The first line contains a single integer $t(1 \leq t \leq 10^3)$, the number of the testcases.

The first line of each testcase contains two numbers $n$ and $m(1 \leq n \leq 18, 0 \leq m \leq n(n-1))$.

Then $m$ lines follow, each line contains two numbers $a$ and $b(1 \leq a,b \leq n, a \neq b)$, which describes a dependency relationship: library $a$ relies on $b$.

The input guarantees that each dependency relationship will occur at most once and there are at most $20 $ testcases with $n > 12$.
 

Output
For each testcase, output a single line with a single number: the answer.
 

Sample Input
3 3 2 1 2 2 3 3 3 1 2 2 3 3 1 5 7 1 2 2 3 3 5 5 4 4 2 2 5 3 1
 

Sample Output
3 4 6
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-25 13:52:16, Gzip enabled