| Udmurt SU Contest 2010 |
|---|
| Закончено |
Compare all vertices of a finite vertex-labeled directed graph in which every vertex has at most one outgoing edge.
Two vertices are equal if they cannot be distinguished by the following process:
Please note, when the process reports vertices are equal, it implies that vertices cannot be distinguished.
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$): the number of vertices.
The following $$$n$$$ lines describe vertices. Each description contains a lowercase English letter (vertex label) and number $$$t$$$ separated by space. $$$t = 0$$$ means that vertex has no outgoing edges. Otherwise, it has an edge to $$$t$$$-th vertex. Vertices are numbered from $$$1$$$ to $$$n$$$ in the order they given.
Output exactly $$$n$$$ lines.
On the $$$i$$$-th line write the equality class number of the $$$i$$$-th vertex. Equal vertices should have the same class number.
Classes are numbered as follows: the first vertex belongs to the first class, the next vertex that doesn't belong to the first class belongs to the second class, and so on.
4 a 2 b 3 b 0 b 3
1 2 3 2
| Название |
|---|


