传统题 1000ms 256MiB

Elden Ring II——艾尔登法环 II

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Statement

In the Elden Ring, there's a well-known landmark called the "Royal City Sewers." This complex structure is a must-see for many experienced soul Ass and novice tarnished. It consists of nn rooms and a number of two-way corridors. Each room has up to three doors, and corridors lead from behind the room doors to other rooms. All corridors in each room lead to different rooms. The entire sewer is interconnected, meaning you can travel between any two rooms, though you may need to pass through other rooms.

You need help labeling the doors to make exploration easier. The idea is that if a room uu has dud_u doors leading to other rooms, these doors will be labeled 1,2,,du1, 2, \cdots, d_u, and then all players will follow a simple procedure. If they are in room uu at the start of their exploration, they will choose the door labeled 1 and go through the corresponding corridor. If they are in room uu and enter from the corridor through a door labeled ii, they will choose the door labeled with the next number (i.e., i+1i + 1 if i<dui < d_u, or 1 if i=dui = d_u) and go through the corresponding corridor.

Now that we have the labeling set, you need to find the number of different corridors that the players will go through if they start their exploration from each room, assuming they follow the rules and walk long enough.

Input

The first line contains an integer nn (3n2×1053 \leq n \leq 2 \times 10^5), which represents the number of rooms in the sewers.

The next nn lines contain descriptions of all the corridors, with line uu describing the corridor connecting room uu to the others. It begins with an integer dud_u (1du31 \leq d_u \leq 3), indicating the number of doors in that room. Next are dud_u integers v1,v2,,vduv_1, v_2 , \cdots, v_{d_u}, giving the room numbers (1vin,viu,(1 \leq v_i \leq n, v_i \neq u, and vivjv_i \neq v_j if iji \neq j) to which these doors lead, in the order of their assigned numbers.

Note that all corridors are bidirectional, so if there is a door from room uu to room vv, then there is also a door from room vv to room uu.

Output

Output nn lines, where line ii contains the number of different corridors the player will visit if they start in room ii.

Samples

6
3 4 2 3
3 5 1 3
3 6 1 2
1 1
1 2
1 3
5
4
5
5
4
5

Notes

The figure below shows the player's path starting from node 1. The numbers marked on the dark blue and light blue arrows indicate the player's path in step ii. This shows that the player passes through five different corridors.

2025 JSUT Collegiate Programming Contest 江苏理工学院新生赛-同步赛

未参加
状态
已结束
规则
ACM/ICPC
题目
15
开始于
2025-11-8 12:00
结束于
2025-11-8 17:00
持续时间
5 小时
主持人
参赛人数
15