답안 #135334

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135334 2019-07-24T03:35:33 Z dragonslayerit Chase (CEOI17_chase) C++14
40 / 100
4000 ms 53400 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;

std::vector<long long> dfs(int node,int parent=-1){
  std::vector<long long> res(V+1,0);
  for(int i=1;i<=V;i++){
    res[i]=ss[node];
  }
  for(int child:adj[node]){
    if(child==parent) continue;
    auto partial=dfs(child,node);
    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];
  }
  long long ans=0;
  for(int i=0;i<N;i++){
    setmax(ans,dfs(i)[V]);
  }
  printf("%lld\n",ans);
}

Compilation message

chase.cpp: In function 'int main()':
chase.cpp:32: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:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&ps[i]);
     ~~~~~^~~~~~~~~~~~~
chase.cpp:38: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 4 ms 2680 KB Output is correct
3 Correct 4 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 4 ms 2680 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 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 4 ms 2680 KB Output is correct
7 Correct 675 ms 3468 KB Output is correct
8 Correct 75 ms 2808 KB Output is correct
9 Correct 68 ms 2796 KB Output is correct
10 Correct 416 ms 2680 KB Output is correct
11 Correct 162 ms 2680 KB Output is correct
12 Correct 91 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4021 ms 53400 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 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 4 ms 2680 KB Output is correct
7 Correct 675 ms 3468 KB Output is correct
8 Correct 75 ms 2808 KB Output is correct
9 Correct 68 ms 2796 KB Output is correct
10 Correct 416 ms 2680 KB Output is correct
11 Correct 162 ms 2680 KB Output is correct
12 Correct 91 ms 2808 KB Output is correct
13 Execution timed out 4021 ms 53400 KB Time limit exceeded
14 Halted 0 ms 0 KB -