Submission #1871740
Source Code Expand
#include<bits/stdc++.h> using namespace std; int n,x[5010],y[5010]; int tote,FIR[5010],TO[5010],NEXT[5010]; bool vis[5010]; void addedge(int u,int v) { TO[++tote]=v; NEXT[tote]=FIR[u]; FIR[u]=tote; } bool dfs(int u) { memset(vis,0,sizeof(vis)); vis[0]=1; int i,S0=0,S1=0; for (int p=FIR[u];p;p=NEXT[p]) { int v=TO[p]; if (!dfs(v)) return 0; S0+=min(x[v],y[v]); S1+=max(x[v],y[v]); int tmp=abs(x[v]-y[v]); for (i=5000-tmp;i>=0;i--) vis[i+tmp]|=vis[i]; } if (S0>x[u]) return 0; for (i=x[u]-S0;i>=0;i--) if (vis[i]) {y[u]=S1-i; break;} return 1; } int main() { #ifdef h10 freopen("E.in","r",stdin); freopen("E.out","w",stdout); #endif int i,f; scanf("%d",&n); for (i=2;i<=n;i++) { scanf("%d",&f); addedge(f,i); } for (i=1;i<=n;i++) scanf("%d",&x[i]); puts(dfs(1)?"POSSIBLE":"IMPOSSIBLE"); }
Submission Info
Submission Time | |
---|---|
Task | E - Bichrome Tree |
User | h10 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 888 Byte |
Status | WA |
Exec Time | 6 ms |
Memory | 256 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:43:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:46:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&f); ^ ./Main.cpp:50:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&x[i]); ^
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 6 ms | 256 KB |
02.txt | AC | 2 ms | 256 KB |
03.txt | AC | 1 ms | 256 KB |
04.txt | WA | 6 ms | 256 KB |
05.txt | WA | 6 ms | 256 KB |
06.txt | WA | 6 ms | 256 KB |
07.txt | AC | 6 ms | 256 KB |
08.txt | WA | 6 ms | 256 KB |
09.txt | AC | 6 ms | 256 KB |
10.txt | AC | 1 ms | 256 KB |
11.txt | AC | 2 ms | 256 KB |
12.txt | WA | 4 ms | 256 KB |
13.txt | WA | 3 ms | 256 KB |
14.txt | AC | 6 ms | 256 KB |
15.txt | WA | 2 ms | 256 KB |
16.txt | WA | 2 ms | 256 KB |
17.txt | AC | 1 ms | 256 KB |
18.txt | AC | 1 ms | 256 KB |
19.txt | AC | 6 ms | 256 KB |
20.txt | AC | 6 ms | 256 KB |
21.txt | AC | 2 ms | 256 KB |
22.txt | AC | 2 ms | 256 KB |
23.txt | AC | 6 ms | 256 KB |
24.txt | AC | 6 ms | 256 KB |
25.txt | AC | 6 ms | 256 KB |
26.txt | WA | 2 ms | 256 KB |
27.txt | WA | 2 ms | 256 KB |
28.txt | WA | 3 ms | 256 KB |
29.txt | WA | 3 ms | 256 KB |
30.txt | WA | 3 ms | 256 KB |
31.txt | WA | 2 ms | 256 KB |
32.txt | WA | 2 ms | 256 KB |
33.txt | AC | 2 ms | 256 KB |
34.txt | AC | 1 ms | 256 KB |
35.txt | AC | 1 ms | 256 KB |
36.txt | AC | 2 ms | 256 KB |
37.txt | AC | 2 ms | 256 KB |
38.txt | AC | 1 ms | 256 KB |
39.txt | AC | 1 ms | 256 KB |
40.txt | AC | 2 ms | 256 KB |
subtask0_0.txt | AC | 1 ms | 256 KB |
subtask0_1.txt | AC | 1 ms | 256 KB |
subtask0_2.txt | AC | 1 ms | 256 KB |
subtask0_3.txt | AC | 1 ms | 256 KB |