Problem Statement

Aoki loves numerical sequences and trees.

One day, Takahashi gave him an integer sequence of length Na1,a2,…,aN, which made him want to construct a tree.

Aoki wants to construct a tree with N vertices numbered 1 through N, such that for each i=1,2,…,N, the distance between vertex i and the farthest vertex from it is ai, assuming that the length of each edge is 1.

Determine whether such a tree exists.

Constraints

  • 2≦N≦100
  • 1≦aiN−1

Input

The input is given from Standard Input in the following format:

  1. N
  2. a1 a2 aN

Output

If there exists a tree that satisfies the condition, print Possible. Otherwise, print Impossible.

Sample Input 1

  1. 5
  2. 3 2 2 3 3

Sample Output 1

  1. Possible

The diagram above shows an example of a tree that satisfies the conditions. The red arrows show paths from each vertex to the farthest vertex from it.

Sample Input 2

  1. 3
  2. 1 1 2

Sample Output 2

  1. Impossible

Sample Input 3

  1. 10
  2. 1 2 2 2 2 2 2 2 2 2

Sample Output 3

  1. Possible

Sample Input 4

  1. 10
  2. 1 1 2 2 2 2 2 2 2 2

Sample Output 4

  1. Impossible

Sample Input 5

  1. 6
  2. 1 1 1 1 1 5

Sample Output 5

  1. Impossible

Sample Input 6

  1. 5
  2. 4 3 2 3 4

Sample Output 6

  1. Possible
  2.  
  3. 把直径构造出来,然后讨论讨论就好了
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. const int maxn=205;
  5.  
  6. int cnt[maxn],n,now,M;
  7.  
  8. int main(){
  9. scanf("%d",&n);
  10. for(int i=1;i<=n;i++){
  11. scanf("%d",&now);
  12. M=max(M,now);
  13. cnt[now]++;
  14. }
  15.  
  16. for(int i=M;i>M-i;i--)
  17. if(cnt[i]<2){ puts("Impossible"); return 0;}
  18.  
  19. if(!(M&1)&&cnt[M>>1]!=1){ puts("Impossible"); return 0;}
  20. if((M&1)&&cnt[M-(M>>1)]!=2){ puts("Impossible"); return 0;}
  21.  
  22. puts("Possible");
  23. return 0;
  24. }

  

  1.  

AtCoder - 2061 Tree Restoring的更多相关文章

  1. Tree Restoring

    Tree Restoring Time limit : 2sec / Memory limit : 256MB Score : 700 points Problem Statement Aoki lo ...

  2. ZOJ 3965 Binary Tree Restoring

    Binary Tree Restoring 思路: 递归 比较a序列和b序列中表示同一个子树的一段区间,不断递归 代码: #include<bits/stdc++.h> using nam ...

  3. zoj 3965 Binary Tree Restoring(搜索)

    Binary Tree Restoring Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge Given two ...

  4. AtCoder Grand Contest 005 C - Tree Restoring

    题目传送门:https://agc005.contest.atcoder.jp/tasks/agc005_c 题目大意: 给定一个长度为\(N\)的整数序列\(A_i\),问能否构造一个\(N\)个节 ...

  5. 2017浙江省赛 H - Binary Tree Restoring ZOJ - 3965

    地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3965 题目: iven two depth-first-search ...

  6. AtCoder AGC030B Tree Burning

    题目链接 https://atcoder.jp/contests/agc030/tasks/agc030_b 题解 细节好题.. 首先假设第一步往右走,那么可以发现当拐弯的次数一定时路径是唯一的 于是 ...

  7. [AGC005C]Tree Restoring 构造

    Description ​ 给出一个数组a,要求构造一颗树,使节点x距离最远的点的距离为\(a_x\). Input ​ 第一行一个正整数NN(2≤N≤1002≤N≤100) ​ 接下来一行,有NN个 ...

  8. ZOJ3965 Binary Tree Restoring

    ZOJ3965 给定一颗二叉树的两种DFS序列 输出一种可能的二叉树的结构. 考察树的递归性质,不要想的太复杂. 当前节点在两个串中后面的节点假如不同则能确认两个子树,如果相同则把下个点作当前点的一个 ...

  9. AtCoder Grand Contest 005

    AtCoder Grand Contest 005 A - STring 翻译 给定一个只包含\(ST\)的字符串,如果出现了连续的\(ST\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 ...

随机推荐

  1. ext radiogroup如何取值和设值

    var radios = Ext.create('Ext.form.Panel', { title: 'RadioGroup Example', width: 300, height: 125, bo ...

  2. Ubuntu下使用mysqli-connect连接mysql时报错:ERROR 1698 (28000): Access denied for user 'root'@'localhost'

    LNMP安装好后,写了个index.php文件,里面的内容很简单,就是想测试php与mysql的通信是否正常,代码如下: <?php $host = 'localhost'; $user = ' ...

  3. HDU 5670

    Machine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  4. HDU1151:Air Raid(最小边覆盖)

    Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  5. POJ1459:Power Network(多源点多汇点的最大流)

    Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 31086   Accepted: 15986 题 ...

  6. Python之日志操作(logging)

    import logging   1.自定义日志级别,日志格式,输出位置 logging.basicConfig( level=logging.DEBUG, format='%(asctime)s | ...

  7. Linux下只允许用户远程scp

    本文将介绍在Linux环境下,让用户不能远程登录 只能使用scp命令 使用到的软件:rssh(http://pizzashack.org/rssh/index.shtml ) 环境:centos6.x ...

  8. input输入浮动提示

    html代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  9. 【BZOJ2742】【HEOI2012】Akai的数学作业 [数论]

    Akai的数学作业 Time Limit: 10 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 这里是广袤无垠的宇宙这里 ...

  10. bzoj 1012 基础线段树

    原题传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1012 今儿一天状态不好,都没怎么刷题..快下课了,刷道水题.... 裸的线段树 /*** ...