Submission #853336

# Submission time Handle Problem Language Result Execution time Memory
853336 2023-09-24T07:26:27 Z manizare Chase (CEOI17_chase) C++14
0 / 100
32 ms 11648 KB
#include <bits/stdc++.h> 
 
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define Pii pair< pii , pii >
#define ll long long
 
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int maxn = 1e5 + 10 , maxq = 1e7 + 1 ,  inf = 1e8 + 10 , mod= 998244353 ,lg = 20 ;
int dis[maxn] , k , n  , w[maxn] ,sm[maxn]; 
vector <int> G[maxn] ;
int ans= 0 ; 

void dfs(int v, int p =0 ){
  sm[v] += sm[p] ;
  for(int i =0 ; i < G[v].size() ; i++){
    int u =G[v][i] ;
    if(u == p)continue ;
    dis[u] = dis[v]+ 1 ;
    sm[v] += w[u] ;
  }
  if(k >= dis[v]){
    ans = max(ans ,sm[v]) ;
  }
  for(int i =0 ; i < G[v].size() ; i++){
    int u =G[v][i] ;
    if(u == p)continue ;
    dfs(u, v);  
  }
}

signed main(){
  ios::sync_with_stdio(false); cin.tie(0) ;
  cin >> n >> k ;
  for(int i = 1; i <= n ; i++){
    cin >> w[i] ;
  }
  for(int i = 1; i < n; i++){
    int v, u ;
    cin >> v>> u ;
    G[v].pb(u);G[u].pb(v) ; 
  }
  dis[1] = 1; 
  dfs(1) ;
  cout << ans ; 
}
/*
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
*/

Compilation message

chase.cpp: In function 'void dfs(int, int)':
chase.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |   for(int i =0 ; i < G[v].size() ; i++){
      |                  ~~^~~~~~~~~~~~~
chase.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i =0 ; i < G[v].size() ; i++){
      |                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 11648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -