Submission #1030883

# Submission time Handle Problem Language Result Execution time Memory
1030883 2024-07-22T11:18:59 Z Unforgettablepl Security Guard (JOI23_guard) C++17
37 / 100
803 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long



int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,m,q;
	cin >> n >> m >> q;
	vector<int> arr(n+1);
	for(int i=1;i<=n;i++)cin>>arr[i];
	vector<vector<int>> adj(n+1);
	for(int i=1;i<n;i++){
		int a,b;
		cin >> a >> b;
		adj[a].emplace_back(b);
		adj[b].emplace_back(a);
	}
	int ans = 0;
	int currmax = 0;
	function<void(int,int,int)> dfs = [&](int x,int p,int curr){
		ans+=arr[p];
		curr+=arr[p];
		curr-=arr[x];
		currmax=max(currmax,-curr);
		for(int&i:adj[x])if(i!=p)dfs(i,x,curr);
	};
	dfs(1,0,arr[1]);
	cout << ans+currmax << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 56 ms 34844 KB Output is correct
3 Correct 59 ms 34900 KB Output is correct
4 Correct 55 ms 34712 KB Output is correct
5 Correct 60 ms 34644 KB Output is correct
6 Correct 57 ms 34648 KB Output is correct
7 Correct 56 ms 34640 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 56 ms 34844 KB Output is correct
3 Correct 59 ms 34900 KB Output is correct
4 Correct 55 ms 34712 KB Output is correct
5 Correct 60 ms 34644 KB Output is correct
6 Correct 57 ms 34648 KB Output is correct
7 Correct 56 ms 34640 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 60 ms 34696 KB Output is correct
11 Correct 62 ms 34716 KB Output is correct
12 Correct 64 ms 34656 KB Output is correct
13 Correct 59 ms 34640 KB Output is correct
14 Correct 59 ms 34644 KB Output is correct
15 Correct 58 ms 34784 KB Output is correct
16 Correct 60 ms 34848 KB Output is correct
17 Correct 63 ms 34640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 56 ms 34844 KB Output is correct
3 Correct 59 ms 34900 KB Output is correct
4 Correct 55 ms 34712 KB Output is correct
5 Correct 60 ms 34644 KB Output is correct
6 Correct 57 ms 34648 KB Output is correct
7 Correct 56 ms 34640 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 60 ms 34696 KB Output is correct
11 Correct 62 ms 34716 KB Output is correct
12 Correct 64 ms 34656 KB Output is correct
13 Correct 59 ms 34640 KB Output is correct
14 Correct 59 ms 34644 KB Output is correct
15 Correct 58 ms 34784 KB Output is correct
16 Correct 60 ms 34848 KB Output is correct
17 Correct 63 ms 34640 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 79 ms 27620 KB Output is correct
20 Correct 90 ms 22356 KB Output is correct
21 Correct 67 ms 14088 KB Output is correct
22 Correct 68 ms 14160 KB Output is correct
23 Correct 59 ms 14672 KB Output is correct
24 Correct 59 ms 14932 KB Output is correct
25 Correct 66 ms 14412 KB Output is correct
26 Correct 57 ms 14396 KB Output is correct
27 Correct 49 ms 14532 KB Output is correct
28 Correct 75 ms 28648 KB Output is correct
29 Correct 72 ms 23824 KB Output is correct
30 Correct 57 ms 17352 KB Output is correct
31 Correct 50 ms 14528 KB Output is correct
32 Correct 57 ms 14544 KB Output is correct
33 Correct 68 ms 15184 KB Output is correct
34 Correct 71 ms 14076 KB Output is correct
35 Correct 72 ms 14932 KB Output is correct
36 Correct 63 ms 14932 KB Output is correct
37 Correct 66 ms 14928 KB Output is correct
38 Correct 73 ms 22272 KB Output is correct
39 Correct 66 ms 24516 KB Output is correct
40 Correct 71 ms 18496 KB Output is correct
41 Correct 91 ms 33876 KB Output is correct
42 Correct 88 ms 34224 KB Output is correct
43 Correct 67 ms 14192 KB Output is correct
44 Correct 68 ms 14160 KB Output is correct
45 Correct 62 ms 14060 KB Output is correct
46 Correct 72 ms 13952 KB Output is correct
47 Correct 65 ms 14160 KB Output is correct
48 Correct 71 ms 14000 KB Output is correct
49 Correct 67 ms 13980 KB Output is correct
50 Correct 67 ms 14176 KB Output is correct
51 Correct 62 ms 14160 KB Output is correct
52 Correct 61 ms 14160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 56 ms 34844 KB Output is correct
3 Correct 59 ms 34900 KB Output is correct
4 Correct 55 ms 34712 KB Output is correct
5 Correct 60 ms 34644 KB Output is correct
6 Correct 57 ms 34648 KB Output is correct
7 Correct 56 ms 34640 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 60 ms 34696 KB Output is correct
11 Correct 62 ms 34716 KB Output is correct
12 Correct 64 ms 34656 KB Output is correct
13 Correct 59 ms 34640 KB Output is correct
14 Correct 59 ms 34644 KB Output is correct
15 Correct 58 ms 34784 KB Output is correct
16 Correct 60 ms 34848 KB Output is correct
17 Correct 63 ms 34640 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 79 ms 27620 KB Output is correct
20 Correct 90 ms 22356 KB Output is correct
21 Correct 67 ms 14088 KB Output is correct
22 Correct 68 ms 14160 KB Output is correct
23 Correct 59 ms 14672 KB Output is correct
24 Correct 59 ms 14932 KB Output is correct
25 Correct 66 ms 14412 KB Output is correct
26 Correct 57 ms 14396 KB Output is correct
27 Correct 49 ms 14532 KB Output is correct
28 Correct 75 ms 28648 KB Output is correct
29 Correct 72 ms 23824 KB Output is correct
30 Correct 57 ms 17352 KB Output is correct
31 Correct 50 ms 14528 KB Output is correct
32 Correct 57 ms 14544 KB Output is correct
33 Correct 68 ms 15184 KB Output is correct
34 Correct 71 ms 14076 KB Output is correct
35 Correct 72 ms 14932 KB Output is correct
36 Correct 63 ms 14932 KB Output is correct
37 Correct 66 ms 14928 KB Output is correct
38 Correct 73 ms 22272 KB Output is correct
39 Correct 66 ms 24516 KB Output is correct
40 Correct 71 ms 18496 KB Output is correct
41 Correct 91 ms 33876 KB Output is correct
42 Correct 88 ms 34224 KB Output is correct
43 Correct 67 ms 14192 KB Output is correct
44 Correct 68 ms 14160 KB Output is correct
45 Correct 62 ms 14060 KB Output is correct
46 Correct 72 ms 13952 KB Output is correct
47 Correct 65 ms 14160 KB Output is correct
48 Correct 71 ms 14000 KB Output is correct
49 Correct 67 ms 13980 KB Output is correct
50 Correct 67 ms 14176 KB Output is correct
51 Correct 62 ms 14160 KB Output is correct
52 Correct 61 ms 14160 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Runtime error 803 ms 1048576 KB Execution killed with signal 9
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 56 ms 34844 KB Output is correct
3 Correct 59 ms 34900 KB Output is correct
4 Correct 55 ms 34712 KB Output is correct
5 Correct 60 ms 34644 KB Output is correct
6 Correct 57 ms 34648 KB Output is correct
7 Correct 56 ms 34640 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 60 ms 34696 KB Output is correct
11 Correct 62 ms 34716 KB Output is correct
12 Correct 64 ms 34656 KB Output is correct
13 Correct 59 ms 34640 KB Output is correct
14 Correct 59 ms 34644 KB Output is correct
15 Correct 58 ms 34784 KB Output is correct
16 Correct 60 ms 34848 KB Output is correct
17 Correct 63 ms 34640 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 79 ms 27620 KB Output is correct
20 Correct 90 ms 22356 KB Output is correct
21 Correct 67 ms 14088 KB Output is correct
22 Correct 68 ms 14160 KB Output is correct
23 Correct 59 ms 14672 KB Output is correct
24 Correct 59 ms 14932 KB Output is correct
25 Correct 66 ms 14412 KB Output is correct
26 Correct 57 ms 14396 KB Output is correct
27 Correct 49 ms 14532 KB Output is correct
28 Correct 75 ms 28648 KB Output is correct
29 Correct 72 ms 23824 KB Output is correct
30 Correct 57 ms 17352 KB Output is correct
31 Correct 50 ms 14528 KB Output is correct
32 Correct 57 ms 14544 KB Output is correct
33 Correct 68 ms 15184 KB Output is correct
34 Correct 71 ms 14076 KB Output is correct
35 Correct 72 ms 14932 KB Output is correct
36 Correct 63 ms 14932 KB Output is correct
37 Correct 66 ms 14928 KB Output is correct
38 Correct 73 ms 22272 KB Output is correct
39 Correct 66 ms 24516 KB Output is correct
40 Correct 71 ms 18496 KB Output is correct
41 Correct 91 ms 33876 KB Output is correct
42 Correct 88 ms 34224 KB Output is correct
43 Correct 67 ms 14192 KB Output is correct
44 Correct 68 ms 14160 KB Output is correct
45 Correct 62 ms 14060 KB Output is correct
46 Correct 72 ms 13952 KB Output is correct
47 Correct 65 ms 14160 KB Output is correct
48 Correct 71 ms 14000 KB Output is correct
49 Correct 67 ms 13980 KB Output is correct
50 Correct 67 ms 14176 KB Output is correct
51 Correct 62 ms 14160 KB Output is correct
52 Correct 61 ms 14160 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Runtime error 803 ms 1048576 KB Execution killed with signal 9
55 Halted 0 ms 0 KB -