답안 #135342

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135342 2019-07-24T03:55:25 Z dragonslayerit Chase (CEOI17_chase) C++14
100 / 100
689 ms 139148 KB
#include <cstdio>
#include <vector>
#include <algorithm>

void setmax(long long& x,long long y){
  x=std::max(x,y);
}

int ps[100005];
long long ss[100005];
std::vector<int> adj[100005];
int V;

long long ans=0;

std::vector<long long> dfs(int node,int parent,std::vector<long long> up){
  std::vector<long long> res(V+1);
  for(int i=1;i<=V;i++){
    res[i]=ss[node];
  }
  for(int i=V;i>0;i--){
    setmax(up[i],up[i-1]+ss[node]-ps[parent]);
  }
  setmax(ans,up[V]);
  for(int child:adj[node]){
    if(child==parent) continue;
    std::vector<long long> tmp(V+1);
    for(int i=0;i<=V;i++){
      tmp[i]=std::max(res[i],up[i]);
    }
    auto partial=dfs(child,node,tmp);
    for(int i=0;i<=V;i++){
      setmax(res[i],partial[i]);
      if(i) setmax(res[i],partial[i-1]+ss[node]-ps[child]);
    }
  }
  return res;
}

int main(){
  int N;
  scanf("%d %d",&N,&V);
  for(int i=0;i<N;i++){
    scanf("%d",&ps[i]);
  }
  for(int i=0;i<N-1;i++){
    int A,B;
    scanf("%d %d",&A,&B);
    A--,B--;
    adj[A].push_back(B);
    adj[B].push_back(A);
    ss[A]+=ps[B];
    ss[B]+=ps[A];
  }
  dfs(0,N,std::vector<long long>(V+1));
  for(int i=0;i<N;i++){
    std::reverse(adj[i].begin(),adj[i].end());
  }
  dfs(0,N,std::vector<long long>(V+1));
  printf("%lld\n",ans);
}

Compilation message

chase.cpp: In function 'int main()':
chase.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&N,&V);
   ~~~~~^~~~~~~~~~~~~~~
chase.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&ps[i]);
     ~~~~~^~~~~~~~~~~~~
chase.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&A,&B);
     ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 5 ms 2680 KB Output is correct
3 Correct 5 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 5 ms 2680 KB Output is correct
3 Correct 5 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 11 ms 4216 KB Output is correct
8 Correct 6 ms 2936 KB Output is correct
9 Correct 6 ms 2808 KB Output is correct
10 Correct 14 ms 2808 KB Output is correct
11 Correct 6 ms 2808 KB Output is correct
12 Correct 5 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 674 ms 136636 KB Output is correct
2 Correct 689 ms 137284 KB Output is correct
3 Correct 227 ms 9456 KB Output is correct
4 Correct 171 ms 9208 KB Output is correct
5 Correct 296 ms 9412 KB Output is correct
6 Correct 299 ms 9352 KB Output is correct
7 Correct 310 ms 9208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 5 ms 2680 KB Output is correct
3 Correct 5 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 11 ms 4216 KB Output is correct
8 Correct 6 ms 2936 KB Output is correct
9 Correct 6 ms 2808 KB Output is correct
10 Correct 14 ms 2808 KB Output is correct
11 Correct 6 ms 2808 KB Output is correct
12 Correct 5 ms 2680 KB Output is correct
13 Correct 674 ms 136636 KB Output is correct
14 Correct 689 ms 137284 KB Output is correct
15 Correct 227 ms 9456 KB Output is correct
16 Correct 171 ms 9208 KB Output is correct
17 Correct 296 ms 9412 KB Output is correct
18 Correct 299 ms 9352 KB Output is correct
19 Correct 310 ms 9208 KB Output is correct
20 Correct 311 ms 9344 KB Output is correct
21 Correct 161 ms 9208 KB Output is correct
22 Correct 326 ms 9252 KB Output is correct
23 Correct 130 ms 9336 KB Output is correct
24 Correct 296 ms 9308 KB Output is correct
25 Correct 225 ms 9044 KB Output is correct
26 Correct 674 ms 139148 KB Output is correct
27 Correct 678 ms 139128 KB Output is correct