- محدودیت زمان: ۱ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
It will be the greatest event of all times, yes… you’ve guessed right… it’s SHAMIR’S BIRTHDAY PARTYYYY!!!
But unfortunately, Shamir is very lonely and he is not in a party mood right now, poor Shamir. So he wants to invite as minimum of his friends as possible (at least one!) as long as no one gets sad. One would get sad if he/she misses someone. Yes as you’ve realized this problem is also love-related. So if Shamir invites a person, he has to invite all of his/her crushes too.
- “what a
b****** p*** a**
”, Shamir said.
You, as a genius programmer (like AmirShams) should help Shamir Figure it out. you will be given the crushes-list of every person that possibly can come to party. You should determine what’s the minimum number of people Shamir should invite so that no one during the party get upset and miss some other bastards. So help Shamir! (Remember, Shamir has to invite someone)
ورودی
The first line of input shows the number of test cases $T$. $$1 \leq T \leq 10$$
Each test case contains two space separated integers $N$ and $M$ indicating Shamir’s friends (and their friends too) and number of crushes lists respectively and is followed by $M$ lines. $$1 \leq N, M \leq 100 , 000$$
Each of following $M$ lines there will be two integers $U$ and $V$ indicating $U$ has a crush over $V$. $$1 \leq U \neq V \leq N$$
Shamir friends are weird like him. don’t care about his friends genders. so Triangle-love is possible!
خروجی
For each test case, print the minimum number of Shamir’s friends that should come to the party so that anyone will have a good time in the party (and possibly outside the party).
مثالها
ورودی نمونه ۱
1
4 4
1 2
2 4
4 1
2 3
خروجی نمونه ۱
1
ارسال پاسخ برای این سؤال