제출 #101398

#제출 시각아이디문제언어결과실행 시간메모리
101398dwscChase (CEOI17_chase)C++14
0 / 100
140 ms9436 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int n,v; int p[100010]; vector<int> adj[100010]; int dp(int x,int dist,int pa){ // cout << x << " " << dist << " " << pa << '\n'; int ans = 0; int sum = 0; for (int i = 0; i < adj[x].size(); i++){ int nx = adj[x][i]; if (nx == pa) continue; sum += p[nx]; } // cout << sum << "\n"; if (dist == 0) return sum; for (int i = 0; i < adj[x].size(); i++){ int nx = adj[x][i]; if (nx== pa) continue; ans = max(ans,dp(nx,dist-1,x)+sum-p[nx]); } return ans; } main(){ cin >> n >> v; for (int i = 0; i < n; i++){ cin >> p[i]; } for (int i = 0; i < n-1; i++){ int a,b; cin >> a >> b; a--; b--; adj[a].push_back(b); adj[b].push_back(a); } if (n <= 1000){ int ans = 0; for (int i = 0; i < n; i++){ // cout << dp(i,v,-1) << "\n"; ans = max(ans,dp(i,v,-1)); } cout << ans; } else cout << dp(0,v,-1); }

컴파일 시 표준 에러 (stderr) 메시지

chase.cpp: In function 'long long int dp(long long int, long long int, long long int)':
chase.cpp:11:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < adj[x].size(); i++){
                     ~~^~~~~~~~~~~~~~~
chase.cpp:18:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < adj[x].size(); i++){
                     ~~^~~~~~~~~~~~~~~
chase.cpp: At global scope:
chase.cpp:26:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...