# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
939236 |
2024-03-06T07:16:47 Z |
vjudge1 |
Chase (CEOI17_chase) |
C++17 |
|
4000 ms |
24148 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define f first
#define int long long
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
const int N=3e5 + 5 ;
const int inf = 1e17 + 7;
const int mod = 998244353;
int n,m,k,ans = -inf;
int u;
vector<int>g[N],a(N),b(N),c(N),d(N);
void dfs(int x, int pr, int cnt1){
cnt1 += c[x];
if(b[x] == 1){
for(auto to:g[x]){
c[x] += c[to];
c[to] = 0;
}
}
d[x] = cnt1;
for(auto to:g[x]){
if(to == pr)continue;
dfs(to,x,cnt1);
}
}
void dfs1(int x, int pr, int cnt2){
cnt2 += c[x];
umax(ans,cnt2-d[x]);
for(auto to:g[x]){
if(to != pr)dfs1(to,x,cnt2);
}
}
/*
12 2
2 3 3 8 1 5 6 7 8 3 5 4
2 1
2 7
3 4
4 7
7 6
5 6
6 8
6 9
7 10
10 11
10 12
*/
void solve(){
cin>>n>>m;
for(int i = 1;i<=n;i++){
cin>>a[i];
}
for(int i = 1;i<n;i++){
int a,b;
cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
}
for(int i = 1;i<=n;i++){
for(int mask = 0;mask<(1<<n);mask++){
if(__builtin_popcount(mask) > m)continue;
for(int j = 1;j<=n;j++){
b[j] = 0;
c[j] = a[j];
d[j] = 0;
}
for(int j = 0;j<n;j++){
if(((mask>>j)&1) == 1){
b[j + 1] = 1;
}
}
u = i;
dfs(i,-1,0);
dfs1(i,-1,0);
}
}
cout<<ans<<"\n";
}
signed main()
{
// freopen("seq.in", "r", stdin);
// freopen("seq.out", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int tt=1;//cin>>tt>>n;
while(tt--)solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
16732 KB |
Output is correct |
2 |
Correct |
6 ms |
16732 KB |
Output is correct |
3 |
Correct |
5 ms |
16732 KB |
Output is correct |
4 |
Correct |
7 ms |
16732 KB |
Output is correct |
5 |
Correct |
7 ms |
16732 KB |
Output is correct |
6 |
Correct |
6 ms |
16732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
16732 KB |
Output is correct |
2 |
Correct |
6 ms |
16732 KB |
Output is correct |
3 |
Correct |
5 ms |
16732 KB |
Output is correct |
4 |
Correct |
7 ms |
16732 KB |
Output is correct |
5 |
Correct |
7 ms |
16732 KB |
Output is correct |
6 |
Correct |
6 ms |
16732 KB |
Output is correct |
7 |
Incorrect |
3760 ms |
16960 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4041 ms |
24148 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
16732 KB |
Output is correct |
2 |
Correct |
6 ms |
16732 KB |
Output is correct |
3 |
Correct |
5 ms |
16732 KB |
Output is correct |
4 |
Correct |
7 ms |
16732 KB |
Output is correct |
5 |
Correct |
7 ms |
16732 KB |
Output is correct |
6 |
Correct |
6 ms |
16732 KB |
Output is correct |
7 |
Incorrect |
3760 ms |
16960 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |