# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
91814 | 2018-12-30T07:34:53 Z | SamAnd | 바이오칩 (IZhO12_biochips) | C++17 | 2000 ms | 30892 KB |
#pragma comment(linker,"/STACK:200000000") #define _CRT_SECURE_NO_WARNINGS #define mp make_pair #include <iostream> #include <algorithm> #include <cstdio> #include <vector> #include <map> #include <set> #include <queue> #include <list> #include <stack> #include <string> #include <cstring> void fp(); void sp(); using namespace std; const int N=200003; int n,m,pp; vector<int> a[N]; int b[N]; int v[N]; map<int,int> ans[N]; void dfs(int x,int p) { if(x==2) cout<<""; for(int i=0;i<a[x].size();++i) { int h=a[x][i]; if(h==p) continue; dfs(h,x); } if(!a[x].empty()) v[x]=v[a[x][0]]; else { v[x]=x; ans[x][0]=0; } for(int i=1;i<a[x].size();++i) { ans[0].clear(); int h=a[x][i]; for(map<int,int>::iterator it1=ans[v[h]].begin();it1!=ans[v[h]].end();++it1) { for(map<int,int>::iterator it2=ans[v[x]].begin();it2!=ans[v[x]].end();++it2) { if(it1->first+it2->first<=m) { ans[0][it1->first+it2->first]=max(ans[0][it1->first+it2->first],it1->second+it2->second); } } } ans[v[x]]=ans[0]; } ans[v[x]][1]=max(ans[v[x]][1],b[x]); } int main() { //fp(); ios_base::sync_with_stdio(false); cin>>n>>m; for(int i=1;i<=n;++i) { int p,x; cin>>p>>x; a[p].push_back(i); b[i]=x; if(p==0) pp=i; } dfs(pp,0); cout<<ans[v[pp]][m]<<endl; return 0; } void fp() { #ifndef OLYMP freopen("d.in","r",stdin); freopen("d.out","w",stdout); #endif } void sp() { #ifdef OLYMP system("pause"); #endif }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 14540 KB | Output is correct |
2 | Correct | 14 ms | 14456 KB | Output is correct |
3 | Correct | 14 ms | 14456 KB | Output is correct |
4 | Correct | 41 ms | 15800 KB | Output is correct |
5 | Correct | 64 ms | 15992 KB | Output is correct |
6 | Correct | 79 ms | 16120 KB | Output is correct |
7 | Execution timed out | 2082 ms | 30892 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |