hdu 5423 Rikka with Tree(水)
来源:互联网 发布:企查查数据接口 编辑:程序博客网 时间:2024/06/16 12:16
题目链接:hdu 5423 Rikka with Tree
#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int maxn = 1005;int N, D[maxn], V[maxn];vector<int> G[maxn];void dfs (int u, int d) {D[d]++;V[u] = 1;for (int i = 0; i < G[u].size(); i++) {int v = G[u][i];if (V[v]) continue;dfs(v, d + 1);}}void init () {memset(D, 0, sizeof(D));memset(V, 0, sizeof(V));for (int i = 0; i <= N; i++) G[i].clear();int u, v;for (int i = 1; i < N; i++) {scanf("%d%d", &u, &v);G[u].push_back(v);G[v].push_back(u);}dfs(1, 0);}bool judge () {for (int i = 0; i < N-1 && D[i]; i++) {if (D[i] > 1 && D[i+1]) return false;}return true;;}int main () {while (scanf("%d", &N) == 1) {init();printf("%s\n", judge() ? "YES" : "NO");}return 0;}
0 0
- hdu 5423 Rikka with Tree(水)
- HDU 5423 Rikka with Tree(构造)
- hdu 5423 Rikka with Tree(深搜)
- hdu 5423 Rikka with Tree(dfs)
- HDU 5423 Rikka with Tree(DFS)
- hdu 5423 Rikka with Tree(思路)
- hdu 5423 Rikka with Tree
- hdu 5423 Rikka with Tree
- hdu 5423 Rikka with Tree
- HDU 5423 Rikka with Tree
- Rikka with Tree HDU
- HDU 5423 Rikka with Tree (树,详解)
- HDU 5423:Rikka with Tree Dijkstra算法
- HDU 5423 Rikka with Tree(水题)
- hdu 5423 Rikka with Tree 乱搞
- hdu 5423 Rikka with Tree DFS
- HDU-5423 Rikka with Tree。树深搜
- HDU~5423 Rikka with Tree(思路+搜索)
- Eclipse中离线安装ADT插件
- webservice几个知识点
- sql 总结
- LoadRunner性能测试样例分析
- 将HTML做成APK
- hdu 5423 Rikka with Tree(水)
- Java语言基础——06.集合框架(1)集合框架概述和List、Set集合
- CF 432D(kmp)
- mac macbook应用清单
- I2C上拉电阻取值问题
- openjdk 初步调试
- [objective-c]_[performSelector的使用]
- hdu 5424 Rikka with Graph II(欧拉通路)
- 第0014道练习题_Python写Excel文件(openpyxl库)