답안 #975086

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975086 2024-05-04T11:57:53 Z 8pete8 Security Guard (JOI23_guard) C++17
37 / 100
124 ms 23076 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
#include <cstdlib> 
#include <cstdint>
using namespace std;
#define ll long long
#define f first
//#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define int long long
#define double long double
const int mxn=2e5,inf=1e18,minf=-1e18;
int val[mxn+10],ans=0;
vector<int>adj[mxn+10];
void dfs(int cur,int p){
	ans+=(val[cur]*(adj[cur].size()-(!!p)));
	for(auto i:adj[cur])if(i!=p)dfs(i,cur);
}
int32_t main(){
	fastio
	int n,m,q;cin>>n>>m>>q;
	if(m!=n-1||q!=0)return 0;
	for(int i=1;i<=n;i++)cin>>val[i];
	for(int i=0;i<n-1;i++){
		int a,b;cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	pair<pii,int> st={{minf,0},-1};
	for(int i=1;i<=n;i++)st=max(st,{{val[i],-adj[i].size()},i});
	dfs(st.s,0);
	cout<<ans;
	return 0;
}
/*
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 51 ms 21408 KB Output is correct
3 Correct 53 ms 21328 KB Output is correct
4 Correct 57 ms 21224 KB Output is correct
5 Correct 51 ms 21332 KB Output is correct
6 Correct 53 ms 21192 KB Output is correct
7 Correct 51 ms 21328 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 51 ms 21408 KB Output is correct
3 Correct 53 ms 21328 KB Output is correct
4 Correct 57 ms 21224 KB Output is correct
5 Correct 51 ms 21332 KB Output is correct
6 Correct 53 ms 21192 KB Output is correct
7 Correct 51 ms 21328 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 57 ms 20684 KB Output is correct
11 Correct 59 ms 23076 KB Output is correct
12 Correct 67 ms 22840 KB Output is correct
13 Correct 58 ms 22872 KB Output is correct
14 Correct 71 ms 22992 KB Output is correct
15 Correct 64 ms 22816 KB Output is correct
16 Correct 58 ms 22300 KB Output is correct
17 Correct 70 ms 22556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 51 ms 21408 KB Output is correct
3 Correct 53 ms 21328 KB Output is correct
4 Correct 57 ms 21224 KB Output is correct
5 Correct 51 ms 21332 KB Output is correct
6 Correct 53 ms 21192 KB Output is correct
7 Correct 51 ms 21328 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 57 ms 20684 KB Output is correct
11 Correct 59 ms 23076 KB Output is correct
12 Correct 67 ms 22840 KB Output is correct
13 Correct 58 ms 22872 KB Output is correct
14 Correct 71 ms 22992 KB Output is correct
15 Correct 64 ms 22816 KB Output is correct
16 Correct 58 ms 22300 KB Output is correct
17 Correct 70 ms 22556 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 88 ms 21148 KB Output is correct
20 Correct 90 ms 20704 KB Output is correct
21 Correct 85 ms 18240 KB Output is correct
22 Correct 79 ms 18576 KB Output is correct
23 Correct 67 ms 19024 KB Output is correct
24 Correct 76 ms 19640 KB Output is correct
25 Correct 61 ms 18876 KB Output is correct
26 Correct 61 ms 18748 KB Output is correct
27 Correct 55 ms 18884 KB Output is correct
28 Correct 89 ms 22120 KB Output is correct
29 Correct 92 ms 19956 KB Output is correct
30 Correct 76 ms 19616 KB Output is correct
31 Correct 57 ms 18884 KB Output is correct
32 Correct 81 ms 18868 KB Output is correct
33 Correct 85 ms 18892 KB Output is correct
34 Correct 83 ms 18480 KB Output is correct
35 Correct 81 ms 19536 KB Output is correct
36 Correct 67 ms 19748 KB Output is correct
37 Correct 83 ms 19556 KB Output is correct
38 Correct 91 ms 21000 KB Output is correct
39 Correct 74 ms 20536 KB Output is correct
40 Correct 87 ms 19456 KB Output is correct
41 Correct 89 ms 22100 KB Output is correct
42 Correct 124 ms 22092 KB Output is correct
43 Correct 83 ms 18572 KB Output is correct
44 Correct 80 ms 18512 KB Output is correct
45 Correct 80 ms 18516 KB Output is correct
46 Correct 96 ms 18520 KB Output is correct
47 Correct 93 ms 18772 KB Output is correct
48 Correct 76 ms 18512 KB Output is correct
49 Correct 88 ms 18516 KB Output is correct
50 Correct 106 ms 18512 KB Output is correct
51 Correct 84 ms 18772 KB Output is correct
52 Correct 73 ms 16960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 51 ms 21408 KB Output is correct
3 Correct 53 ms 21328 KB Output is correct
4 Correct 57 ms 21224 KB Output is correct
5 Correct 51 ms 21332 KB Output is correct
6 Correct 53 ms 21192 KB Output is correct
7 Correct 51 ms 21328 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 57 ms 20684 KB Output is correct
11 Correct 59 ms 23076 KB Output is correct
12 Correct 67 ms 22840 KB Output is correct
13 Correct 58 ms 22872 KB Output is correct
14 Correct 71 ms 22992 KB Output is correct
15 Correct 64 ms 22816 KB Output is correct
16 Correct 58 ms 22300 KB Output is correct
17 Correct 70 ms 22556 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 88 ms 21148 KB Output is correct
20 Correct 90 ms 20704 KB Output is correct
21 Correct 85 ms 18240 KB Output is correct
22 Correct 79 ms 18576 KB Output is correct
23 Correct 67 ms 19024 KB Output is correct
24 Correct 76 ms 19640 KB Output is correct
25 Correct 61 ms 18876 KB Output is correct
26 Correct 61 ms 18748 KB Output is correct
27 Correct 55 ms 18884 KB Output is correct
28 Correct 89 ms 22120 KB Output is correct
29 Correct 92 ms 19956 KB Output is correct
30 Correct 76 ms 19616 KB Output is correct
31 Correct 57 ms 18884 KB Output is correct
32 Correct 81 ms 18868 KB Output is correct
33 Correct 85 ms 18892 KB Output is correct
34 Correct 83 ms 18480 KB Output is correct
35 Correct 81 ms 19536 KB Output is correct
36 Correct 67 ms 19748 KB Output is correct
37 Correct 83 ms 19556 KB Output is correct
38 Correct 91 ms 21000 KB Output is correct
39 Correct 74 ms 20536 KB Output is correct
40 Correct 87 ms 19456 KB Output is correct
41 Correct 89 ms 22100 KB Output is correct
42 Correct 124 ms 22092 KB Output is correct
43 Correct 83 ms 18572 KB Output is correct
44 Correct 80 ms 18512 KB Output is correct
45 Correct 80 ms 18516 KB Output is correct
46 Correct 96 ms 18520 KB Output is correct
47 Correct 93 ms 18772 KB Output is correct
48 Correct 76 ms 18512 KB Output is correct
49 Correct 88 ms 18516 KB Output is correct
50 Correct 106 ms 18512 KB Output is correct
51 Correct 84 ms 18772 KB Output is correct
52 Correct 73 ms 16960 KB Output is correct
53 Incorrect 1 ms 4956 KB Output isn't correct
54 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Incorrect 1 ms 4956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Incorrect 1 ms 4956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 51 ms 21408 KB Output is correct
3 Correct 53 ms 21328 KB Output is correct
4 Correct 57 ms 21224 KB Output is correct
5 Correct 51 ms 21332 KB Output is correct
6 Correct 53 ms 21192 KB Output is correct
7 Correct 51 ms 21328 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 57 ms 20684 KB Output is correct
11 Correct 59 ms 23076 KB Output is correct
12 Correct 67 ms 22840 KB Output is correct
13 Correct 58 ms 22872 KB Output is correct
14 Correct 71 ms 22992 KB Output is correct
15 Correct 64 ms 22816 KB Output is correct
16 Correct 58 ms 22300 KB Output is correct
17 Correct 70 ms 22556 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 88 ms 21148 KB Output is correct
20 Correct 90 ms 20704 KB Output is correct
21 Correct 85 ms 18240 KB Output is correct
22 Correct 79 ms 18576 KB Output is correct
23 Correct 67 ms 19024 KB Output is correct
24 Correct 76 ms 19640 KB Output is correct
25 Correct 61 ms 18876 KB Output is correct
26 Correct 61 ms 18748 KB Output is correct
27 Correct 55 ms 18884 KB Output is correct
28 Correct 89 ms 22120 KB Output is correct
29 Correct 92 ms 19956 KB Output is correct
30 Correct 76 ms 19616 KB Output is correct
31 Correct 57 ms 18884 KB Output is correct
32 Correct 81 ms 18868 KB Output is correct
33 Correct 85 ms 18892 KB Output is correct
34 Correct 83 ms 18480 KB Output is correct
35 Correct 81 ms 19536 KB Output is correct
36 Correct 67 ms 19748 KB Output is correct
37 Correct 83 ms 19556 KB Output is correct
38 Correct 91 ms 21000 KB Output is correct
39 Correct 74 ms 20536 KB Output is correct
40 Correct 87 ms 19456 KB Output is correct
41 Correct 89 ms 22100 KB Output is correct
42 Correct 124 ms 22092 KB Output is correct
43 Correct 83 ms 18572 KB Output is correct
44 Correct 80 ms 18512 KB Output is correct
45 Correct 80 ms 18516 KB Output is correct
46 Correct 96 ms 18520 KB Output is correct
47 Correct 93 ms 18772 KB Output is correct
48 Correct 76 ms 18512 KB Output is correct
49 Correct 88 ms 18516 KB Output is correct
50 Correct 106 ms 18512 KB Output is correct
51 Correct 84 ms 18772 KB Output is correct
52 Correct 73 ms 16960 KB Output is correct
53 Incorrect 1 ms 4956 KB Output isn't correct
54 Halted 0 ms 0 KB -