답안 #571564

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
571564 2022-06-02T11:09:28 Z teki Paprike (COI18_paprike) C++11
0 / 100
43 ms 15112 KB
#include <bits/stdc++.h>

typedef long long ll;

#define pb push_back
#define MS(x,y) memset((x),(y),sizeof((x)))
#define MN 1000000001

using namespace std;

const int nsize = 100001;
int n,m,q;
int sajz[nsize];
vector<int> pat[nsize];
int vred[nsize];

bool custComp(int a, int b) {
    if (sajz[a] == sajz[b]) return a < b;

    return sajz[a] > sajz[b];
}

int res = 1;
int ctr = 0;

void dfs(int pos, int parent) {
    int bris = pat[pos].size()-1;

    for (auto it:pat[pos]) {
        if (it == parent) continue;

        dfs(it,pos);
    }

    sort(pat[pos].begin(),pat[pos].end());
    for (auto it2:pat[pos]) {
        if (it2 == parent) continue;
        auto it = sajz[it2];

        if (sajz[pos]+it <= q) {
            sajz[pos] += it;
            bris--;
        } else {
            res += bris;
            return;
        }
    }
}

int main()
{
    #if LOCAL_DEBUG
        fstream cin("in.txt");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int zbir = 0;

    cin>>n>>q;
    m = n-1;

    for (int i = 0; i<n; i++) cin>>vred[i];
    for (int i = 0; i<n; i++) zbir += vred[i];

    for (int i = 0; i<m; i++) {
        int a,b;
        cin>>a>>b;
        a--; b--;

        pat[a].pb(b);
        pat[b].pb(a);
    }

    for (int i = 0; i<n; i++) sajz[i] = vred[i];

    dfs(0,-1);

    if (zbir <= q) {
        cout<<0<<endl;
        return 0;
    }

    cout<<res<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 15112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -