제출 #1207023

#제출 시각아이디문제언어결과실행 시간메모리
1207023em4ma2바이오칩 (IZhO12_biochips)C++20
50 / 100
501 ms401172 KiB
// اللهم صل على محمد وعلى ال محمد كما صليت على ابراهيم وعلى ال ابراهيم انك حميد مجيد #include "bits/stdc++.h" using namespace std; #define ll long long //#define int long long #define pb push_back #define applejuice ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); const int mod=1e9+7; const ll inf=1e17; const int mxsz=2e5+4; const int off=1<<20; const int siz=504; vector<int>adj[mxsz]; int vis[mxsz]; int a[mxsz]; int dp[mxsz][siz]; int sz[mxsz]; void dfs(int i){ vis[i]=1; for (auto x:adj[i]){ if (!vis[x]){ dfs(x); sz[i]+=sz[x]; } } } void tra(int i,int m){ vis[i]=1; for (auto x:adj[i]) { if (!vis[x])tra(x,m); //cout<<"sdj;"; for (int j = m; j >=0; j--) { for (int l = min(sz[x],j); l >=0; l--) { dp[i][j]=max(dp[i][j],dp[x][l]+dp[i][j-l]); } } } dp[i][1]=max(dp[i][1],a[i]); } signed main(){ applejuice; int n,m; cin>>n>>m; int root; for (int i=1;i<=n;i++){ int p, x; cin>>p>>x; a[i]=x; if (p==0)root=i; adj[p].pb(i); } for (int i=0;i<=n;i++){ for (int j=0;j<=m;j++){ dp[i][j]=-inf; } } for (int i=0;i<=n;i++){ dp[i][0]=0; } /*for (int i=1;i<=n;i++){ if (adj[i].size()==0){ dp[i][1]=a[i]; } }*/ for (int i=1;i<=n;i++){ sz[i]=1; } dfs(root); for (int i=0;i<=n;i++)vis[i]=0; tra(root,m); /*for (int i=1;i<n;i++){ for (int j=1;j<=m;j++){ cout<<dp[i][j]<<" "; } }*/ cout<<dp[root][m]<<endl; }

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

biochips.cpp: In function 'int main()':
biochips.cpp:62:22: warning: overflow in conversion from 'long long int' to 'int' changes value from '-100000000000000000' to '-1569325056' [-Woverflow]
   62 |             dp[i][j]=-inf;
      |                      ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...