시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 240 103 68 39.306%

문제

제주도는 관광객들이 많이 찾는 도시이다. 제주도에는 교차로가 N개, 일방통행 도로 M개가 있다. 각각의 도로는 한 교차로와 다른 교차로를 연결한다. 한 교차로 쌍을 연결하는 도로의 개수가 여러 개일 수 있다.

사실 제주도의 도로는 매우 신기한 형태로 건설되었다. 한 교차로에서 도로를 따라 돌아다니다가 시작한 교차로로 돌아오는 일은 불가능하다. (그럼 제주도에 사는 사람들은 어떻게 출퇴근을 하는 것일까?)

두 그룹이 제주도를 여행할 계획을 세우고 있다. 각 그룹은 한 교차로에서 여행을 시작해 도로를 따라 다니면서 여행을 할 것이다. 하지만, 두 그룹은 사이가 매우 좋지 않기 때문에, 같은 교차로를 공유하면 안된다. 즉, 두 경로 P1, P2를 구해야 하는데, 각각의 Pi (1 ≤ i ≤ 2)는 한 교차로 si에서 시작해서 ti에서 여행을 마쳐야 하고, 중간에 공유하는 교차로가 있으면 안된다. 경로의 시작점과 도착점도 겹치면 안된다. 하지만, Pi가 교차로를 하나만 포함하는 경우는 가능하다. (si = ti)

두 계획을 세우는데, 두 경로에 포함된 교차로 수의 합을 최대로 하는 프로그램을 작성하시오.

입력

첫째 줄에 테스트 케이스의 개수 T (1 ≤ T ≤ 10)가 주어진다.

각 테스트 케이스의 첫째 줄에는 교차로의 수 N과 도로의 수 M이 주어진다. (1 ≤ N ≤ 300, 1 ≤ M ≤ 3000) 교차로는 1번부터 N번까지 번호가 매겨져 있다. 다음 M개의 줄에는 도로의 정보를 나타내는 A와 B가 주어지며, A에서 B로 향하는 일방통행 도로라는 뜻이다.

출력

각 테스트 케이스마다, 문제의 조건을 만족하면서, 두 경로에 포함된 교차로의 최대 개수를 한 줄에 하나씩 출력한다.

예제 입력 1

3
3 2
1 2
2 3
8 9
1 2
2 3
3 4
5 6
6 7
7 8
2 6
6 3
3 7
4 2
1 2
3 4

예제 출력 1

3
8
4
W3sicHJvYmxlbV9pZ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