# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
796102 |
2023-07-28T06:25:56 Z |
박영우(#10072) |
Security Guard (JOI23_guard) |
C++17 |
|
80 ms |
32408 KB |
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 301010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
vector<int> adj[MAX];
ll C[MAX];
ll rem[MAX];
ll ans = 0;
void dfs(int x, int p = 0) {
if (adj[x].size() == 1 && p) {
rem[x] = C[x];
ans += C[x];
return;
}
for (auto v : adj[x]) if (v != p) {
dfs(v, x);
if (rem[v] >= C[x]) rem[x] += rem[v] - C[x];
}
for (auto v : adj[x]) if (v != p) {
if (rem[v] < C[x]) {
rem[x] -= C[x] - rem[v];
ans += C[x] - rem[v];
}
}
if (rem[x] < 0) {
ans -= rem[x];
rem[x] = 0;
}
if (!p) return;
if (rem[x] < C[x]) {
ans += C[x] - rem[x];
rem[x] = C[x];
}
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, M, Q;
cin >> N >> M >> Q;
int i;
for (i = 1; i <= N; i++) cin >> C[i];
int a, b;
for (i = 1; i < N; i++) {
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1);
cout << ans << ln;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
68 ms |
32400 KB |
Output is correct |
3 |
Correct |
80 ms |
32408 KB |
Output is correct |
4 |
Incorrect |
61 ms |
32376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
68 ms |
32400 KB |
Output is correct |
3 |
Correct |
80 ms |
32408 KB |
Output is correct |
4 |
Incorrect |
61 ms |
32376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
68 ms |
32400 KB |
Output is correct |
3 |
Correct |
80 ms |
32408 KB |
Output is correct |
4 |
Incorrect |
61 ms |
32376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
68 ms |
32400 KB |
Output is correct |
3 |
Correct |
80 ms |
32408 KB |
Output is correct |
4 |
Incorrect |
61 ms |
32376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Incorrect |
3 ms |
7380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Incorrect |
3 ms |
7380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
68 ms |
32400 KB |
Output is correct |
3 |
Correct |
80 ms |
32408 KB |
Output is correct |
4 |
Incorrect |
61 ms |
32376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |