A10756 | Recover a functional graph
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
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.
输出格式
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.
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.
输入输出样例
输入 #1
3 0 3 0 3 ? ?
输出 #1
2 3 1
输入 #2
5 3 2 ? ? ? ? ? ? ? ?
输出 #2
5 3 2 2 4
输入 #3
8 ? 3 ? ? 0 2 0 2 0 3 0 3 0 3 3 3
输出 #3
5 1 4 3 6 7 5 2
输入 #4
1 ? ?
输出 #4
1
输入 #5
6 0 3 0 3 0 3 0 3 0 3 0 3
输出 #5
2 3 1 5 6 4
输入 #6
2 1 1 1 1
输出 #6
-1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted