제출 #891210

#제출 시각아이디문제언어결과실행 시간메모리
891210cpptowinChase (CEOI17_chase)C++17
0 / 100
149 ms144464 KiB
#include<bits/stdc++.h> #define fo(i,d,c) for(int i=d;i<=c;i++) #define fod(i,c,d) for(int i=c;i>=d;i--) #define maxn 100010 #define N 1010 #define fi first #define se second #define pb emplace_back #define en cout<<"\n"; #define int long long #define inf (int)1e18 #define pii pair<int,int> #define vii vector<pii> #define lb(x) x&-x #define bit(i,j) ((i>>j)&1) #define offbit(i,j) (i^(1<<j)) #define onbit(i,j) (i|(1<<j)) #define vi vector<int> template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } using namespace std; int n,V; vi ke[maxn]; int p[maxn],s[maxn]; int up[maxn][110],down[maxn][110]; int ans; void dfs(int u,int parent) { up[u][1] = s[u]; for(int v : ke[u]) { if(v == parent) continue; dfs(v,u); fo(i,1,V) ans = max(ans,up[u][i] + down[v][V - i]); fo(i,1,V) { up[u][i] = max({up[u][i],up[v][i],up[v][i - 1] + s[u] - p[v]}); down[u][i] = max({down[u][i],down[v][i],down[u][i - 1] + s[u] - p[parent]}); } } reverse(ke[u].begin(),ke[u].end()); fo(i,1,V) up[u][i] = 0; up[u][1] = s[u]; for(int v : ke[u]) { if(v == parent) continue; fo(i,1,V) ans = max(ans,up[u][i] + down[v][V - i]); fo(i,1,V) { up[u][i] = max({up[u][i],up[v][i],up[v][i - 1] + s[u] - p[v]}); down[u][i] = max({down[u][i],down[v][i],down[v][i - 1] + s[u] - p[parent]}); } } } main() { #define name "TASK" if(fopen(name".inp","r")) { freopen(name".inp","r",stdin); freopen(name".out","w",stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> V; fo(i,1,n) cin >> p[i]; fo(i,1,n - 1) { int u,v; cin >> u >> v; ke[u].pb(v); ke[v].pb(u); s[v] += p[u]; s[u] += p[v]; } dfs(1,0); cout << ans; }

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

chase.cpp:71:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   71 | main()
      | ^~~~
chase.cpp: In function 'int main()':
chase.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
chase.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...