UESTC 2016 Summer Training #1 J - Objects Panel (A) 按条件遍历树

Posted Aragaki

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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) 按条件遍历树的主要内容,如果未能解决你的问题,请参考以下文章

uestc summer training #2

uestc summer training #3 线段树优化建边

2016 UESTC Training for Data Structures

2016 UESTC Training for Dynamic Programming

BZOJ4896 [Thu Summer Camp2016]补退选

「LYOI2016 Summer」Equation 题解