1 条题解
-
0
C++ :
#include <stdio.h> #include <algorithm> #include <string> #include <map> #include <vector> #include <iostream> #include <queue> #include <string.h> using namespace std; struct NODE{ int lchild,rchild; }node[1024]; int lchild[1024],rchild[1024],vis[1024],MAX=-1; void dfs(int root,int x){ vis[root]=1; if(x>MAX) MAX=x; if(lchild[root]!=0&&vis[lchild[root]]==false){ node[root].lchild=lchild[root]; dfs(lchild[root],2*x); } if(rchild[root]!=0&&vis[rchild[root]]==false){ node[root].rchild=rchild[root]; dfs(rchild[root],2*x+1); } } int main(){ int n,root; scanf("%d%d",&n,&root); int a,b; for(int i=1;i<n;i++){ scanf("%d%d",&a,&b); lchild[a]=b; rchild[b]=a; } dfs(root,1); if(MAX==n) printf("yes"); else printf("no"); return 0; }
- 1
信息
- ID
- 910
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- (无)
- 递交数
- 0
- 已通过
- 0
- 上传者