304907: CF932C. Permutation Cycle
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Permutation Cycle
题意翻译
**【题意】:** 我们有一个序列$P$,对于任意整数$i(1 \leq i \leq N)$,满足$1 \leq P_i \leq N$。 我们定义一个函数$f$,其中$f_{i,j}$的值满足: - 当$j=1$时,$f_{i,j}=P_i$。 - 当$j\neq 1$时,$f_{i,j}=f_{P_i,j-1}$。 我们记$G_i$表示令$f_{i,j}=i$成立的最小的$j$。我们可以证明$G_i$是一定存在的。 输入$N,A,B$。$A,B$表示$G_i$只能等于$A$或$B$。求一个可能的$P$,使得对于任意$i(1 \leq i \leq N)$,都有$f_{i,j}=i$。 **【输入格式】:** 一行,三个数,$N,A,B$。 **【输出格式】:** 输出$N$个数,表示一个可能的$P$的取值。若有多解,输出任意一个皆可。题目描述
For a permutation $ P[1...\ N] $ of integers from $ 1 $ to $ N $ , function $ f $ is defined as follows: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF932C/115260490bb6a358f1e02860b5ea4f22462a7ef1.png)Let $ g(i) $ be the minimum positive integer $ j $ such that $ f(i,j)=i $ . We can show such $ j $ always exists. For given $ N,A,B $ , find a permutation $ P $ of integers from $ 1 $ to $ N $ such that for $ 1<=i<=N $ , $ g(i) $ equals either $ A $ or $ B $ .输入输出格式
输入格式
The only line contains three integers $ N,A,B $ ( $ 1<=N<=10^{6},1<=A,B<=N $ ).
输出格式
If no such permutation exists, output -1. Otherwise, output a permutation of integers from $ 1 $ to $ N $ .
输入输出样例
输入样例 #1
9 2 5
输出样例 #1
6 5 8 3 4 1 9 2 7
输入样例 #2
3 2 1
输出样例 #2
1 2 3