https://codeforces.com/contest/902/problem/C
题意:
给你树的深度和树的每个节点的深度,问你是否有重构,如果有重构输出两个不同的结构
题解:
如果相邻节点的深度都大于1的话,这两个节点就是某个节点的子树,所以会有同构,输出子节点在同一个父节点上的情况和子节点不在同一个父节点上的情况即可
代码如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <map> #include <set> #include <cmath> #include <ctime> #include <stack> #include <queue> #include <cstdio> #include <cctype> #include <bitset> #include <string> #include <vector> #include <cstring> #include <iostream> #include <algorithm> #include <functional> #define fuck(x) cout<<"["<<x<<"]"; #define FIN freopen("input.txt","r",stdin); #define FOUT freopen("output.txt","w+",stdout); //#pragma comment(linker, "/STACK:102400000,102400000") using namespace std; typedef long long LL; typedef pair<int, int> PII; const int maxn = 3e5+5; const int INF = 0x3f3f3f3f; const int MOD = 1e9+7; int h; int num[maxn]; int main(){ #ifndef ONLINE_JUDGE FIN #endif scanf("%d",&h); num[0]=0; for(int i=1;i<=h+1;i++) scanf("%d",&num[i]); int flag=1; for(int i=1;i<=h;i++){ if(num[i]>1&&num[i+1]>1) flag=0; } if(flag) cout<<"perfect"<<endl; else{ int now=0; printf("ambiguous "); for(int i=1;i<=h+1;i++){ for(int j=0;j<num[i];j++){ printf("%d ",now); } now+=num[i]; } printf(" "); now=0; for(int i=1;i<=h+1;i++){ if(num[i]>1&&num[i-1]>1){ for(int j=1;j<num[i];j++){ printf("%d ",now); } printf("%d ",now-1); }else{ for(int j=0;j<num[i];j++){ printf("%d ",now); } } now+=num[i]; } } }