답안 #46345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46345 2018-04-19T14:12:49 Z RezwanArefin01 Chase (CEOI17_chase) C++17
70 / 100
693 ms 24828 KB
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii; 

const int maxn = 1e5 + 10; 
vector<int> adj[maxn]; 
ll p[maxn], s[maxn], mx;
multiset<ll> st; 
int n, v; 

void solve(int u, int par) {
	st.insert(s[u] - p[par]); 
	ll tot = 0; int tk = v;
	for(auto it = --st.end(); it != st.begin() && tk; it--, tk--) tot += *it; 
	mx = max(mx, tot);
	for(int v : adj[u]) if(v - par) solve(v, u); 
	auto it = st.find(s[u] - p[par]);
	if(it != st.end()) st.erase(it);
}

int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
	freopen("in", "r", stdin);
#endif
	scanf("%d %d", &n, &v);
	for(int i = 1; i <= n; i++) 
		scanf("%lld", &p[i]);

	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v); 
		adj[u].push_back(v);
		adj[v].push_back(u); 
	}
	for(int i = 1; i <= n; i++) {
		for(int v : adj[i]) s[i] += p[v]; 
	}
	if(n > 1000) solve(1, 0);
	else for(int i = 1; i <= n; i++) {
		st.clear(); 
		solve(i, 0);
	} 
	printf("%lld\n", mx); 	
}

Compilation message

chase.cpp: In function 'int main(int, const char**)':
chase.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &v);
  ~~~~~^~~~~~~~~~~~~~~~~
chase.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &p[i]);
   ~~~~~^~~~~~~~~~~~~~~
chase.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v); 
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2876 KB Output is correct
4 Correct 4 ms 2916 KB Output is correct
5 Correct 4 ms 3028 KB Output is correct
6 Correct 4 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2876 KB Output is correct
4 Correct 4 ms 2916 KB Output is correct
5 Correct 4 ms 3028 KB Output is correct
6 Correct 4 ms 3028 KB Output is correct
7 Correct 693 ms 3164 KB Output is correct
8 Correct 233 ms 3276 KB Output is correct
9 Correct 75 ms 3312 KB Output is correct
10 Correct 204 ms 3312 KB Output is correct
11 Correct 203 ms 3380 KB Output is correct
12 Correct 193 ms 3380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 16220 KB Output is correct
2 Correct 255 ms 18288 KB Output is correct
3 Correct 84 ms 18288 KB Output is correct
4 Correct 114 ms 18288 KB Output is correct
5 Correct 135 ms 18556 KB Output is correct
6 Correct 154 ms 20776 KB Output is correct
7 Correct 137 ms 22848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2876 KB Output is correct
4 Correct 4 ms 2916 KB Output is correct
5 Correct 4 ms 3028 KB Output is correct
6 Correct 4 ms 3028 KB Output is correct
7 Correct 693 ms 3164 KB Output is correct
8 Correct 233 ms 3276 KB Output is correct
9 Correct 75 ms 3312 KB Output is correct
10 Correct 204 ms 3312 KB Output is correct
11 Correct 203 ms 3380 KB Output is correct
12 Correct 193 ms 3380 KB Output is correct
13 Correct 235 ms 16220 KB Output is correct
14 Correct 255 ms 18288 KB Output is correct
15 Correct 84 ms 18288 KB Output is correct
16 Correct 114 ms 18288 KB Output is correct
17 Correct 135 ms 18556 KB Output is correct
18 Correct 154 ms 20776 KB Output is correct
19 Correct 137 ms 22848 KB Output is correct
20 Incorrect 115 ms 24828 KB Output isn't correct
21 Halted 0 ms 0 KB -