首页 > 代码库 > UESTC 2016 Summer Training #1 J - Objects Panel (A) 按条件遍历树
UESTC 2016 Summer Training #1 J - Objects Panel (A) 按条件遍历树
#include <iostream> #include <cstdio> #include <vector> using namespace std; typedef long long LL; char s[108]; vector<int> num[108]; void dfs(int u, int k) { int d = num[u].size(), v; for(int i = 0; i < d; i++){ v = num[u][i]; for(int j = 0; j < k; j++) printf(" "); if(num[v].size()){ if(s[v] == ‘-‘){printf("- object%d\n", v); dfs(v, k+1);} else printf("+ object%d\n", v); } else printf(" object%d\n", v); /* if(s[v] == ‘-‘){ if(num[v].size()) {printf("- object%d\n", v); dfs(v, k+1);} else printf(" object%d\n", v); } else if(s[v] == ‘+‘) printf("+ object%d\n", v); */ } } int main() { #ifdef LOCAL freopen("a.txt", "r", stdin); //freopen("b.txt", "w", stdout); int T = 1; while(T--){ #endif // LOCAL int n, k, val; scanf("%d", &n); for(int i = 0; i <= n; i++){ getchar(); scanf("%c", &s[i]); scanf("%d", &k); while(k--){ scanf("%d", &val); num[i].push_back(val); } } if(n == 0) {printf(" project\n");} else{ if(s[0] == ‘-‘){ printf("- project\n"); dfs(0, 1); } else printf("+ project\n"); } #ifdef LOCAL printf("\n"); } #endif // LOCAL return 0; }
UESTC 2016 Summer Training #1 J - Objects Panel (A) 按条件遍历树
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。