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

19816번 - Time Travel 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB7000.000%

문제

In future after the time machine was invented it became easier to learn history. Now you can just go to the corresponding year and watch the events by yourself. Professor uses this device to study the system of Berland roads during the Great Road Transformation.

The transformation took $k$ consectuve years. During these years the system of roads of Berland used to change. There are $n$ cities in the country, numbered from 1ドル$ to $n$. Each year these cities were connected by $n-1$ bidirectional roads, for every pair of cities there was a unique path between them.

Every day Professor chooses two cities $s$ and $f,ドル travels to every year of the Great Road Transformation, one after another, and makes a trip from $s$ to $f$ in this year, visiting all roads on the path, including $s$ and $f$. After that he wrote down the number of cities that were visited in all of his $k$ trips.

Unfortunately, on the day he had completed his work, having had studied all pairs of cities, he lost all of his records. He only has maps of Berland road system for all $k$ of the Great Road Transformation years.

Help Professor to restore the numbers that he had written down for all possible pairs of cities $s$ and $f$.

입력

The first line of input contains two integers $n$ and $k$ --- the number of cities in Berland and the number of years of the Great Road Transformation (1ドル \leq n, k \leq 500$).

Then $k$ descriptions of Berland roads systems follow, one for each year, in the following format: $n-1$ lines of the description contains two integers $a$ and $b$ each --- the cities connected by the roads (1ドル \leq a, b \leq n,ドル $a \neq b$).

It is guaranteed that for each of the $k$ years for each pair of cities there is a unique path between them.

출력

Output $n$ lines, $n$ integers in each of them. The $j$-th number in the $i$-th line must be the number that Professor wrote down if $s=i$ and $f=j$.

제한

예제 입력 1

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

예제 출력 1

1 3 2 2
3 1 3 2
2 3 1 2
2 2 2 1

예제 입력 2

3 3
1 2
2 3
2 3
3 1
3 1
1 2

예제 출력 2

1 2 2
2 1 2
2 2 1

힌트

There are 4ドル$ cities in Berland in the first sample test. There are 2ドル$ years studied by Professor. The map of the road system for the first year is shown on the left, the map for the second year is shown on the right.

Consider the pair of cities $s = 1$ and $f = 2$. Traveling to the first year, Professor visits cities 1ドル,ドル 2ドル,ドル 3ドル,ドル 4ドル$ on his trip. Traveling to the second year, Professor visits cities 1ドル,ドル 2ドル,ドル 4ドル$. So there are 3ドル$ cities 1ドル,ドル 2ドル,ドル 4ドル$ that will be visited in all his trips, so he writes down the number 3ドル$ for this pair of cities.

Consider the pair of cities $s = 3$ and $f = 1$. Traveling to the first year, Professor visits cities 1ドル,ドル 3ドル$ on his trip. Traveling to the second year, Professor visits cities 1ドル,ドル 3ドル,ドル 4ドル$. So there are 2ドル$ cities 1ドル,ドル 3ドル$ that will be visited in all his trips, so he writes down the number 2ドル$ for this pair of cities.

출처

Olympiad > Russian Olympiad in Informatics > Russia Team High School Programming Contest > Russia Team High School Programming Contest 2019 L번

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

출처

대학교 대회

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

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