Submission #1368232


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vec;
typedef vector<vec> graph;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)
bool checked[105];
int trnum[105];
graph g(105);
int tr[105];
int res = 0;
int dfs1(int x){
    if(checked[x]) return;
    checked[x] = true;
    int total_tr = tr[x];
    REP(i, g[x].size()){
        total_tr += dfs1(g[x][i]);
    }
    trnum[x] = total_tr;
    return tolal_tr;
}

void dfs2(int x){
    if(checked[x]) return;
    checked[x] = true;
    REP(i, g[x].size()){
        if(trnum!=0){
            dfs2(g[x][i]);
            res += 2;
        }
    }
}

int main(){
    int n, x;
    cin >> n >> x;
    x--;
    int ma = 0;
    REP(i, n){
        cin >> tr[i];
        ma = max(ma, tr[i]);
    }
    REP(i, n-1){
        int s, t;
        cin >> s >> t;
        s--;
        t--;
        g[s].push_back(t);
        g[t].push_back(s);
    }
    REP(i, n) checked[i] = false;
    REP(i, n) trnum[i] = 0;
    dfs1(x);
    REP(i, n) checked[i] = false;
    dfs2(x);
    cout << res << endl;
    return 0;
}

Submission Info

Submission Time
Task B - ツリーグラフ
User theory_and_me
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1286 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int dfs1(int)’:
./Main.cpp:19:20: error: return-statement with no value, in function returning ‘int’ [-fpermissive]
     if(checked[x]) return;
                    ^
./Main.cpp:26:12: error: ‘tolal_tr’ was not declared in this scope
     return tolal_tr;
            ^