Codeforces Round 381 (Div. 1)
D
Recover a functional graph
Codeforces
3400
原题
← CE →
翻译中…

Functional graph is a directed graph in which all vertices have outdegree equal to $1$. Loops are allowed.

翻译中…

Some vertices of a functional graph lay on a cycle. From the others we can come to a cycle by making a finite number of steps along the edges (we consider only finite functional graphs in this problem).

翻译中…

Let's compute two values for each vertex. $*precycle*_{*i*}$ is the amount of edges we should pass to get to a vertex which is a part of some cycle (zero, if $*i*$ itself lies on a cycle), $*cycle*_{*i*}$ is the length of the cycle we get to.

翻译中…

You are given the information about these values for some functional graph. For each vertex you know the values $*precycle*_{*i*}$ and $*cycle*_{*i*}$, however, instead of some values there can be the question mark. It means that these values are unknown.

翻译中…

Build any functional graph that suits the description or determine that there is no such graph.

翻译中…

Input

翻译中…

The first line contains single integer $*n*$ ($1 ≤ *n* ≤ 300$) — the number of vertices in the graph.

翻译中…

Each of the next $*n*$ lines contain two integers — $*precycle*_{*i*}$ ($0 ≤ *precycle*_{*i*} ≤ *n* - 1$) and $*cycle*_{*i*}$ ($1 ≤ *cycle*_{*i*} ≤ *n*$). There could be question marks instead of some of these values.

翻译中…

Output

翻译中…

In case there is no solution, print -1.

翻译中…

Otherwise, print $*n*$ integers. $*i*$-th of them is the number of vertex to which the edge form the $*i*$-th vertex go.

翻译中…

The vertices should be in the same order as they go in input data.

翻译中…

If there are multiple solutions, print any of them.

翻译中…

样例

Input #1
3
0 3
0 3
? ?
Output #1
2 3 1
InputCopy OutputCopy
Input #2
5
3 2
? ?
? ?
? ?
? ?
Output #2
5 3 2 2 4
InputCopy OutputCopy
Input #3
8
? 3
? ?
0 2
0 2
0 3
0 3
0 3
3 3
Output #3
5 1 4 3 6 7 5 2
InputCopy OutputCopy
Input #4
1
? ?
Output #4
1
InputCopy OutputCopy
Input #5
6
0 3
0 3
0 3
0 3
0 3
0 3
Output #5
2 3 1 5 6 4
InputCopy OutputCopy
Input #6
2
1 1
1 1
Output #6
-1
InputCopy OutputCopy
题目信息
题号
739D
时间限制
2 s
内存限制
256 MB
标签
图匹配

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。