#P9052. [PA 2021] Areny

[PA 2021] Areny

Problem Description

Bajtek received the newest computer game Byte Defence 4 from his parents for Christmas. He excitedly launched the game and started playing. The character he controls is called Bajtonator, who becomes stronger by fighting monsters, completing quests, and upgrading equipment. There are nn special arenas on the map, which contain very rare loot. However, there are also nn types of passes, and to enter an arena you must have the corresponding pass.

The rules of the game are as follows:

  1. If you have the pass for an arena, you can enter that arena and fight monsters. Entering an arena does not consume the pass. Monsters revive after you leave, so the same pass can be used repeatedly to challenge the same arena.
  2. Each arena has a pre-announced, fixed pass pool, and the passes in the pool are never removed or changed. After defeating the monsters in an arena, besides possibly dropping rare items, the game will randomly pick one pass from that arena’s pass pool, make a copy, and give it to you. Therefore, after many victories, you may own multiple copies of the same type of pass.

After reading a guide, Bajtek learned that arenas with larger indices are harder. His strength can be represented by an integer kk: he will certainly win in any arena with index k\le k, and he will certainly lose in any arena with index >k> k.

At the beginning, he has no passes and can only spend money to buy one. Which one is the best to buy?

He believes that if he buys the pass for arena AA, then using this initial pass and the passes obtained from battles afterward, no matter what, he will eventually be able to enter arena BB and win. In that case, this pass is worth buying.

So he wants to know, for a fixed kk, how many ordered pairs of arenas (A,B)(A,B) satisfy:

  1. ABA \ne B.
  2. If he buys only the pass for arena AA, then using this initial pass and the passes obtained from battles afterward, no matter what, he will eventually be able to enter arena BB and win.

You need to compute the number of such ordered pairs (A,B)(A,B) for k=1,2,,nk = 1,2,\cdots,n.

Input Format

The first line contains an integer n  (2n2105)n\;(2\le n\le 2\cdot 10^5), the number of arenas.

The next nn lines describe the pass pools. In the ii-th line, the first integer is li  (1li)l_i\;(1\le l_i), the size of the pass pool of arena ii. Then follow lil_i integers, each denoting the arena index that the corresponding pass allows you to enter. The sum of all lil_i does not exceed 51055\cdot10^5.

Output Format

One line with nn integers, where the ii-th integer is the answer when k=ik = i.

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

Hint

Translated by ChatGPT 5