QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#394993#7684. Sweet Sugarjames1BadCreeperRE 0ms0kbC++141.1kb2024-04-21 00:04:222024-04-21 00:04:22

Judging History

你现在查看的是最新测评结果

  • [2024-04-21 00:04:22]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-04-21 00:04:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5; 

int n, k, ans, a[N], fa[N]; 
int f[N][2], die[N]; 
vector<int> G[N]; 
// f[i][3] 代表子树内个数,那么

void dfs(int x, int ff) {
    f[x][a[x] & 1] = a[x]; f[x][!(a[x] & 1)] = -1e9; 
    for (int y : G[x]) if (y != ff) {
        dfs(y, x); 
        if (!die[y]) {
            int t0 = f[x][0], t1 = f[x][1]; 
            f[x][0] = max({t0, t0 + f[y][0], t1 + f[y][1]}); 
            f[x][1] = max({t1, t1 + f[y][0], t0 + f[y][1]}); 
        }
    }
    if (f[x][k & 1] >= k) die[x] = 1, ++ans; 
}

void solve(void) {
    cin >> n >> k; 
    for (int i = 1; i <= n; ++i) cin >> a[i], G[i].clear(), die[i] = 0; 
    for (int i = 1; i < n; ++i) {
        int u, v; cin >> u >> v; 
        G[u].emplace_back(v); G[v].emplace_back(u); 
    }
    ans = 0; dfs(1, 0); 
    cout << ans << "\n"; 
}

int main(void) {
    freopen("linkcut.in", "r", stdin); 
    freopen("linkcut.out", "w", stdout); 
    
    ios::sync_with_stdio(0); 
    int T; cin >> T; 
    while (T--) solve(); 
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

4
7 5
1 2 1 2 2 1 2
1 2
2 3
3 4
3 5
5 6
5 7
2 2
1 0
1 2
1 1
1
1 2
1

output:


result: