Logo
(追記) (追記ここまで)

29787번 - Railroad Maintenance 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
40 초 (추가 시간 없음) 1024 MB73360.000%

문제

You are in charge of the maintenance of a railroad network. The network consists of $\mathbf{N}$ stations and $\mathbf{L}$ train lines. Each train line serves a fixed list of stations bidirectionally (trains turn around in the first and last stations of the list). Transfers from one line to another in a station are possible, which means a trip in the network from station $a$ to station $b$ is possible if there is a list of train lines such that the first one serves station $a,ドル the last one serves station $b,ドル and for any consecutive pair of train lines in the list there is at least one station that they both serve.

The easiest way to do maintenance is to shut down entire lines, one at a time. However, some train lines may be essential. A train line is essential if removing it would make at least one trip between a pair of stations not possible.

Given the list of existing train lines, calculate how many of them are essential.

입력

The first line of the input gives the number of test cases, $\mathbf{T}$. $\mathbf{T}$ test cases follow. Each test case starts with a line containing two integers $\mathbf{N}$ and $\mathbf{L}$: the number of stations and train lines in the network. Then, $\mathbf{L}$ groups of 2 lines follow. The first line of the $i$-th group contains a single integer $\mathbf{K_i}$ the number of stations served by the $i$-th train line. The second line of the $i$-th group contains $\mathbf{K_i}$ integers $\mathbf{S_{i,1}}, \mathbf{S_{i,2}}, \dots, \mathbf{S_{i,{K_i}}}$ representing the stations served by the $i$-th train line.

출력

For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is the number of train lines that are essential.

제한

  • 1ドル \le \mathbf{T} \le 100$.
  • 2ドル \le \mathbf{K_i} \le \mathbf{N}$ for all $i$.
  • 1ドル \le \mathbf{S_{i,j}} \le \mathbf{N},ドル for all $i, j$.
  • $\mathbf{S_{i,j}} \ne \mathbf{S_{i,j'}},ドル for all $i, j, j'$ such that $j \ne j'$ (Each train line serves a station at most once).
  • The trip between all pairs of stations is possible as per the definition above when no train line is shut down.

Test Set 1 (9점)

  • 2ドル \le \mathbf{N} \le 100$.
  • 1ドル \le \mathbf{L} \le 100$.
  • $\mathbf{K_1} + \mathbf{K_2} + \cdots + \mathbf{K_L} \le 200$.

Test Set 2 (20점)

  • 2ドル \le \mathbf{N} \le 10^5$.
  • 1ドル \le \mathbf{L} \le 10^5$.
  • $\mathbf{K_1} + \mathbf{K_2} + \cdots + \mathbf{K_L} \le 2 \times 10^5$.

예제 입력 1

4
4 3
3
1 2 3
2
1 4
3
4 1 3
4 4
2
1 2
2
3 4
2
3 2
2
4 1
4 3
2
1 2
2
3 4
2
3 2
4 3
2
1 2
2
3 4
4
4 1 2 3

예제 출력 1

Case #1: 1
Case #2: 0
Case #3: 3
Case #4: 1

힌트

In Sample Case #1, the first train line is essential because it is the only one serving station 2ドル$. Since shutting any other line down would not make travel between at least one pair of stations impossible, they are not essential.

In Sample Case #2, no line is essential.

Sample Case #3 is similar to Sample Case #2, but missing the last train line. That makes all remaining train lines essential.

In Sample Case #4, the last train line is essential as there is no way to go from station 1ドル$ to station 4ドル$ without it. As in Sample Case #1, since this train line already connects every station, no other line is essential.

출처

Contest > Google > Code Jam > Google Code Jam Farewell Round > Round B D번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /