Submission #19442403
Source Code Expand
Copy
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; bool dfs(vector<vector<int>> &t,vector<int> &x,vector<int> &mi,int i){ vector<bool> a(x.at(i)+1,0); a[0]=1; int s=0; for(int j:t.at(i)){ if(!dfs(t,x,mi,j)) return 0; s+=x.at(j)+mi.at(j); for(int k=x.at(i);k>=0;k--){ if(!a[k]) continue; a[k]=0; if(k+x.at(j)<=x.at(i)) a[k+x.at(j)]=1; if(k+mi.at(j)<=x.at(i)) a[k+mi.at(j)]=1; } } for(int k=x.at(i);k>=0;k--){ if(a[k]){ mi.at(i)=s-k; return 1; } } return 0; } int main(){ int n; cin>>n; vector<vector<int>> t(n); for(int i=1;i<n;i++){ int p; cin>>p; p--; t.at(p).push_back(i); } vector<int> x(n); for(int i=0;i<n;i++) cin>>x.at(i); vector<int> mi(n); cout<<(dfs(t,x,mi,0)?"POSSIBLE":"IMPOSSIBLE")<<endl; }
Submission Info
Submission Time | |
---|---|
Task | E - Bichrome Tree |
User | l_ength |
Language | C++ (GCC 9.2.1) |
Score | 700 |
Code Size | 936 Byte |
Status | AC |
Exec Time | 15 ms |
Memory | 3872 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask0_3.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask0_3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 7 ms | 3692 KB |
02.txt | AC | 4 ms | 3592 KB |
03.txt | AC | 8 ms | 3872 KB |
04.txt | AC | 4 ms | 3496 KB |
05.txt | AC | 5 ms | 3516 KB |
06.txt | AC | 6 ms | 3572 KB |
07.txt | AC | 6 ms | 3548 KB |
08.txt | AC | 15 ms | 3648 KB |
09.txt | AC | 13 ms | 3500 KB |
10.txt | AC | 3 ms | 3528 KB |
11.txt | AC | 4 ms | 3584 KB |
12.txt | AC | 6 ms | 3480 KB |
13.txt | AC | 7 ms | 3684 KB |
14.txt | AC | 2 ms | 3572 KB |
15.txt | AC | 8 ms | 3760 KB |
16.txt | AC | 3 ms | 3504 KB |
17.txt | AC | 3 ms | 3616 KB |
18.txt | AC | 3 ms | 3692 KB |
19.txt | AC | 3 ms | 3648 KB |
20.txt | AC | 5 ms | 3612 KB |
21.txt | AC | 3 ms | 3728 KB |
22.txt | AC | 4 ms | 3760 KB |
23.txt | AC | 11 ms | 3576 KB |
24.txt | AC | 11 ms | 3700 KB |
25.txt | AC | 7 ms | 3676 KB |
26.txt | AC | 5 ms | 3688 KB |
27.txt | AC | 5 ms | 3728 KB |
28.txt | AC | 7 ms | 3796 KB |
29.txt | AC | 5 ms | 3680 KB |
30.txt | AC | 5 ms | 3780 KB |
31.txt | AC | 6 ms | 3684 KB |
32.txt | AC | 8 ms | 3732 KB |
33.txt | AC | 3 ms | 3584 KB |
34.txt | AC | 3 ms | 3600 KB |
35.txt | AC | 5 ms | 3628 KB |
36.txt | AC | 5 ms | 3736 KB |
37.txt | AC | 2 ms | 3708 KB |
38.txt | AC | 3 ms | 3588 KB |
39.txt | AC | 3 ms | 3620 KB |
40.txt | AC | 3 ms | 3656 KB |
subtask0_0.txt | AC | 2 ms | 3532 KB |
subtask0_1.txt | AC | 2 ms | 3640 KB |
subtask0_2.txt | AC | 2 ms | 3592 KB |
subtask0_3.txt | AC | 5 ms | 3528 KB |