Hiho 国庆出游
来源:互联网 发布:vivo软件招聘 编辑:程序博客网 时间:2024/03/29 16:49
#include<stdio.h>#include<iostream>#include<string.h>#include<vector>#include<algorithm>using namespace std;struct tree{int p[101];int n;tree() :n(0){}};tree tr[101];void insert_tree(int a, int b){tr[a].p[tr[a].n++] = b;tr[b].p[tr[b].n++] = a;}bool through(int a, int b, bool bl[101][101], int aim){bl[a][b] = true;for (int i = 0; i < tr[a].n; ++i){int v = tr[a].p[i];if (b == v)return true;}for (int i = 0; i < tr[a].n; ++i){int v = tr[a].p[i];if (bl[v][b] == true){continue;}if (true == through(v, b, bl, aim)){if (aim == b)return true;continue;}}return false;}void detect(int a[], int n){bool bl[101][101] = { 0 };for (int i = 0; i < n-1; ++i){if (through(a[i], a[i+1], bl, a[n-1]) == false){cout << "NO" << endl;return;}}cout << "YES" << endl;}int main(){int n;cin >> n;for (int i = 0; i < n; ++i){int m;cin >> m;for (int j = 0; j < m-1; ++j){int a, b;cin >> a >> b;insert_tree(a, b);}int o;cin >> o;int* p = new int[o];for (int k = 0; k < o; ++k){cin >> p[k];}detect(p, o);delete []p;memset(&tr, 0, sizeof(tr));}return 0;}
0 0
- Hiho 国庆出游
- hiho国庆出游
- hiho #1041 : 国庆出游
- [hiho]#1041 : 国庆出游 树的前序遍历校验
- 国庆出游
- 国庆出游照片
- 1041 : 国庆出游
- hihocoder 1041 国庆出游
- [HihoCoder]#1041 : 国庆出游
- hihoCoder 1041 国庆出游
- 国庆出游 HihoCoder
- Hiho1041 国庆出游 搜索题解
- hihocoder 1041 国庆出游 dfs
- hihocoder#1041之国庆出游
- 程序员专属国庆出游指南!
- 2017国庆出游的意外
- hihocoder #1041 : 国庆出游
- hihocoder #1041 : 国庆出游 (DFS)
- Pro Android学习笔记(一六五):联系人API(8):控制整合
- LeetCode的medium题集合(C++实现)十三
- C++ 写leetcode遇到的一些问题总结string to integer
- Android Hook学习之ptrace函数的使用
- python爬虫第一课,制作搜索引擎
- Hiho 国庆出游
- Android应用Context详解及源码解析
- Uncaught TypeError: undefined is not a function
- 各种距离算法汇总
- 用c++实现 c++顺序表的实现(采用模板)
- linux下清空文件内容方法
- html输入构输入验证码达到一定位数触发事件及回车时触发事件
- 用Windows自带的画笔工具调整图片的大小
- 开发技术前线 第十一期